Đồng hồ số PIC16F877A with XC8

11:56:00 PM
Chào các bạn trong bài đăng này mình sẽ hướng dẫn các bạn làm đồng hồ số hiển thị led LCD 16x02 sử dụng PIC16F877A và trình biên dịch Mplab XC8 đê viết code.

Ảnh mô phỏng protues.


digit clock pic16f877a xc8


- Đây là code file main.c .

#include "Includes.h"

// Configuration word for PIC16F877A
__CONFIG( FOSC_HS & WDTE_OFF & PWRTE_ON & CP_OFF & BOREN_ON
         & LVP_OFF & CPD_OFF & WRT_OFF & DEBUG_OFF);

// Main Function
void main(void)
{
InitLCD(); // Initialize LCD in 4bit mode
Init1msecTimerInterrupt(); // Start 1 msec timer

while(1)
{
if( msCounter == 0 )        // msCounter becomes zero after exact one sec
{
// Displays time in HH:MM:SS format
DisplayTimeToLCD(hrCounter, minCounter, secCounter);   
}

UpdateTimeCounters();       // Update sec, min, hours counters
  }
}

- Đây là code file timer.c . 

#include "Includes.h"

// define digital clock variables
unsigned int msCounter = 0;
unsigned int secCounter = 0;
unsigned int minCounter = 0;
unsigned int hrCounter = 0;

void InitTimer0(void)
{
// Timer0 is 8bit timer, select T0CS and PSA to be zero
OPTION_REG &= 0xC1;     // Make Prescalar 1:4

T0IE = 1; // Enable Timer0 interrupt
GIE = 1; // Enable global interrupts
}

void Init1msecTimerInterrupt(void)
{
InitTimer0(); // Intialize timer0 to genrate 1msec interrupts
}

void UpdateTimeCounters(void)
{
if (msCounter==1000)
{
secCounter++;
msCounter=0;
}

if(secCounter==60)
{
minCounter++;
secCounter=0;
}

if(minCounter==60)
{
hrCounter++;
minCounter=0;
}

if(hrCounter==24)
{
hrCounter = 0;
}
}

Link download project.
http://adf.ly/11512871/digit-clock-xc8

Share this

Related Posts

  • 0 - 9999 with XC8 LED 7 đoạn hay LED 7 thanh (Seven Segment display) là 1 linh kiện rất phổ dụng , được dùng như là 1 công cụ h
  • Đếm từ 0 - 99 XC8 Hôm nay, chúng ta sẽ cùng nhau làm một số ví dụ về LED 7 thanh để làm rõ hơn những lý thuyết đã tìm hiểu ở bài viết tr
  • Timer 1 with XC8 KHẢO SÁT TIMER TIMER1 CỦA PIC 16F887A  Là bộ định thời/đếm 16 bit gồm 2 thanh ghi 8 bit (TMR1H và TMR1L) – có t
  • Led matrix 5x7 with XC8  I. Ma trận LED.         Ma trận LED tức Dot Matrix LED là tập hợp nhiều đèn

EmoticonEmoticon

:)
:(
=(
^_^
:D
=D
=)D
|o|
@@,
;)
:-bd
:-d
:p
:ng