0% found this document useful (0 votes)
5 views3 pages

LCD

The document contains C code for a PIC16 microcontroller that initializes a timer and manages LED states based on a count variable. It includes interrupt handling for timer events and checks button presses to display messages on an LCD. The main function sets up the ADC and LCD, and enters an infinite loop after initialization.

Uploaded by

Dung Nguyen Dinh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

LCD

The document contains C code for a PIC16 microcontroller that initializes a timer and manages LED states based on a count variable. It includes interrupt handling for timer events and checks button presses to display messages on an LCD. The main function sets up the ADC and LCD, and enters an infinite loop after initialization.

Uploaded by

Dung Nguyen Dinh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <xc.

h>
#include "lcd_hd44780_pic16.h"
#include "ADC0808.h"
#define Input 1
#define Out 0
#define Tris_kb0 TRISAbits.TRISA0;
#define Tris_kb1 TRISAbits.TRISA1;
#define Tris_Led TRISBbits.TRISB0;
#define kb0 PORTAbits.RA0;
#define kb0 PORTAbits.RA1;
#define Led PORTBbits.RB0;
unsigned int count_t0;
void timer0_initialize ()
{
T0CS=0; // Chon CLK0=FOSC/4 =4Mhz T=0.25us
PSA=0; // Co su dung he so chia
PS0=1;
PS1=1;
PS2=0; //He so chia 011=1:16 0.25us*16=4us
TMR0=5; //250 xung tràn tuong ung 1ms
TMR0IE=1; //Cho phep ngat Timer0
GIE=1; // Cho phep toan cuc
}

void __interrupt() Count_Up(void) //1ms


{
if (TMR0IE && TMR0IF)
{
TMR0=5;
TMR0IF=0;
count_t0++;
if(count_t0<1000)
{
Led=0;
}
if(count_t0>=1000&& count_t0<1500)
{
Led=1;
}
if(count_t0>=2=1500&&count_t0<2000)
{
Led=0;
}
If(count_t0>=2=1500&&count_t0<2500)
{
Led=1;
}
If(count_t0>=2500)
Count_t0=0;
If(kb0==1&&kb1==0)
{
LCDGotoXY(1,0);
LCDWriteString("Phim 1 bam ");
LCDGotoXY(1,1);
LCDWriteString(" ");
}
If(kb0==0&&kb1==1)
{
LCDGotoXY(1,0);
LCDWriteString(" ");
LCDGotoXY(1,1);
LCDWriteString(" Phim 2 bam");
}
}
}
int main ()
{
unsigned char Digit[3] = { 0,0,0 }; // To make digits to display on LCD
unsigned int ADC_Value = 0;
ADCON1 = 0x06;
LCDInit(LS_NONE);
InitADC();
LCDClear();
Tris_kb0=1;
Tris_kb1=1;
Tris_led=0;
timer0_initialize ();
while(1)
{

}
}

You might also like