đây là code của e lụm trên google xuống nhưng ko biết chỗ nào là chân tín hiệu của xung vuông vào các bác giúp em với
/*do tan so - copyright@2011NguyenHuuQuang
Mail: Sprintarm@gmail.com
phone 01676184300*/
#include <REGX51.H>
#define RS P2_2 // khai bao chan RS cua lCD
#define RW P2_3 //khai bao chan RW cua LCD
#define E P2_4
#define DATA P0 //dinh nghi PORTD lam chan du lieu cho LCD
void lcd_set(unsigned char lenh); //setting LCD
void lcd_command(unsigned char lenh1); //ghi lenh vao LCD
void lcd_write(unsigned char lenh2); //ghi du lieu vao LCD
void lcd_init();
void lcd_putnum(unsigned long info); //viet so vao LCD
void lcd_Gotoxy(unsigned char x,unsigned char y); //nhay den vi tri x,y trong LCD
void lcd_clear();//ham xoa man hinh trong LCD
void lcd_putchar(unsigned char *s); //ham ghi 1 chuoi ky tu vao LCD
unsigned int Millisec; //bien dem ms
unsigned int so_xung;
unsigned int frequency;
void delay_ms(unsigned int ms) //ham delay
{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<121;j++);
}
void delay_us(unsigned int us)
{
unsigned int i;
for(i=0;i<us;i++);
}
void ISR_1000ms(void) interrupt 1 // ham ngat timer 0
{
TF0 = 0;//xoa co tran
TH0 =0xE2; // nap du lieu vao thanh ghi timer
TL0 =0x0A;
TR0=1;
Millisec++;
if(Millisec==0xFFFD)
Millisec=0;
}
void EXT_INT0(void) interrupt 0
{
so_xung++;
}
void main()
{
IE=0x85;//cho phep ngat ngoai INT0 va INT1
TCON = 0x01; // che do 16 bit tu nap lai
TR0=1; //cho phep timer hoat dong
TH0=0xfc;
TL0=0x18; //nap gia tri cho timer
TR0=1; // cho phép timer 0 hoat dong
TF0=0;
EA=1; //cho phep ngat
ET0=1; //cho phep ngat timer 0
IT0=1;
lcd_init();
while(1)
{
if(Millisec>=1000)
{
Millisec=0;
frequency=so_xung; //so xung trong 1 s dem duoc tu ngat ngoai
so_xung=0;
lcd_Gotoxy(0,1);
lcd_putchar("tan So: ");
lcd_putnum(frequency); //hien thi len LCD tan so do duoc
lcd_putchar(" Hz");
}
}
}
void lcd_set(unsigned char lenh)
{
RS=0;
RW=0;
DATA=lenh;
E=1;
delay_us(50);
E=0;
}
void lcd_command(unsigned char lenh1)
{
// char temp;
RS=0;
RW=0;
DATA=(DATA&0x0F)|(lenh1&0xF0); //temp;
E=1;
delay_us(20);
E=0;
delay_us(20);
DATA=(DATA&0x0F)|((lenh1<<4)&0xF0);
E=1;
delay_us(20);
E=0;
delay_us(50);
}
void lcd_write(unsigned char lenh2)
{
RS=1;
RW=0;
DATA=(DATA&0x0F)|(lenh2&0xF0);
E=1;
delay_us(10);
E=0;
delay_us(10);
RS=1;
RW=0;
delay_us(10);
DATA=(DATA&0x0F)|((lenh2<<4)&0xF0);
E=1;
delay_us(10);
E=0;
delay_us(50);
}
void lcd_init()
{
lcd_set(0x30);
delay_us(50);
lcd_set(0x30);
delay_us(50);
lcd_set(0x30);
delay_us(50);
lcd_set(0x20);
delay_us(50);
//delay_us(50);
lcd_command(0x80);
lcd_command(0x06);
lcd_command(0x08);
lcd_command(0x0C);
lcd_command(0x28);
lcd_command(0x01);
delay_ms(20);
}
void lcd_putchar(unsigned char *s)
{
char i;
for(i=0;s[i]!=0;i++)
{
lcd_write(s[i]);
}
}
void lcd_putnum(unsigned long info) //ham in 1 so len man hinh LCD
{
unsigned int chucnghin,nghin,tram,chuc,donvi;
chucnghin=info/10000;
nghin=(info-chucnghin*10000)/1000;
tram=(info-chucnghin*10000-nghin*1000)/100;
chuc=(info-chucnghin*10000-nghin*1000-100*tram)/10;
donvi= (info-chucnghin*10000-nghin*1000-100*tram-chuc*10);
lcd_write(chucnghin+48);
lcd_write(nghin+48);
lcd_write(tram+48);
lcd_write(chuc+48);
lcd_write(donvi+48);
}
void lcd_Gotoxy(unsigned char x,unsigned char y)//ham nhay dem vi tri x,y trong man hinh lcd
{
char position;
if (y==1)
{
position=0x80;
lcd_command(position|x);
}
else
{
position=0xC0;
lcd_command(position|x);
}
}
/*do tan so - copyright@2011NguyenHuuQuang
Mail: Sprintarm@gmail.com
phone 01676184300*/
#include <REGX51.H>
#define RS P2_2 // khai bao chan RS cua lCD
#define RW P2_3 //khai bao chan RW cua LCD
#define E P2_4
#define DATA P0 //dinh nghi PORTD lam chan du lieu cho LCD
void lcd_set(unsigned char lenh); //setting LCD
void lcd_command(unsigned char lenh1); //ghi lenh vao LCD
void lcd_write(unsigned char lenh2); //ghi du lieu vao LCD
void lcd_init();
void lcd_putnum(unsigned long info); //viet so vao LCD
void lcd_Gotoxy(unsigned char x,unsigned char y); //nhay den vi tri x,y trong LCD
void lcd_clear();//ham xoa man hinh trong LCD
void lcd_putchar(unsigned char *s); //ham ghi 1 chuoi ky tu vao LCD
unsigned int Millisec; //bien dem ms
unsigned int so_xung;
unsigned int frequency;
void delay_ms(unsigned int ms) //ham delay
{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<121;j++);
}
void delay_us(unsigned int us)
{
unsigned int i;
for(i=0;i<us;i++);
}
void ISR_1000ms(void) interrupt 1 // ham ngat timer 0
{
TF0 = 0;//xoa co tran
TH0 =0xE2; // nap du lieu vao thanh ghi timer
TL0 =0x0A;
TR0=1;
Millisec++;
if(Millisec==0xFFFD)
Millisec=0;
}
void EXT_INT0(void) interrupt 0
{
so_xung++;
}
void main()
{
IE=0x85;//cho phep ngat ngoai INT0 va INT1
TCON = 0x01; // che do 16 bit tu nap lai
TR0=1; //cho phep timer hoat dong
TH0=0xfc;
TL0=0x18; //nap gia tri cho timer
TR0=1; // cho phép timer 0 hoat dong
TF0=0;
EA=1; //cho phep ngat
ET0=1; //cho phep ngat timer 0
IT0=1;
lcd_init();
while(1)
{
if(Millisec>=1000)
{
Millisec=0;
frequency=so_xung; //so xung trong 1 s dem duoc tu ngat ngoai
so_xung=0;
lcd_Gotoxy(0,1);
lcd_putchar("tan So: ");
lcd_putnum(frequency); //hien thi len LCD tan so do duoc
lcd_putchar(" Hz");
}
}
}
void lcd_set(unsigned char lenh)
{
RS=0;
RW=0;
DATA=lenh;
E=1;
delay_us(50);
E=0;
}
void lcd_command(unsigned char lenh1)
{
// char temp;
RS=0;
RW=0;
DATA=(DATA&0x0F)|(lenh1&0xF0); //temp;
E=1;
delay_us(20);
E=0;
delay_us(20);
DATA=(DATA&0x0F)|((lenh1<<4)&0xF0);
E=1;
delay_us(20);
E=0;
delay_us(50);
}
void lcd_write(unsigned char lenh2)
{
RS=1;
RW=0;
DATA=(DATA&0x0F)|(lenh2&0xF0);
E=1;
delay_us(10);
E=0;
delay_us(10);
RS=1;
RW=0;
delay_us(10);
DATA=(DATA&0x0F)|((lenh2<<4)&0xF0);
E=1;
delay_us(10);
E=0;
delay_us(50);
}
void lcd_init()
{
lcd_set(0x30);
delay_us(50);
lcd_set(0x30);
delay_us(50);
lcd_set(0x30);
delay_us(50);
lcd_set(0x20);
delay_us(50);
//delay_us(50);
lcd_command(0x80);
lcd_command(0x06);
lcd_command(0x08);
lcd_command(0x0C);
lcd_command(0x28);
lcd_command(0x01);
delay_ms(20);
}
void lcd_putchar(unsigned char *s)
{
char i;
for(i=0;s[i]!=0;i++)
{
lcd_write(s[i]);
}
}
void lcd_putnum(unsigned long info) //ham in 1 so len man hinh LCD
{
unsigned int chucnghin,nghin,tram,chuc,donvi;
chucnghin=info/10000;
nghin=(info-chucnghin*10000)/1000;
tram=(info-chucnghin*10000-nghin*1000)/100;
chuc=(info-chucnghin*10000-nghin*1000-100*tram)/10;
donvi= (info-chucnghin*10000-nghin*1000-100*tram-chuc*10);
lcd_write(chucnghin+48);
lcd_write(nghin+48);
lcd_write(tram+48);
lcd_write(chuc+48);
lcd_write(donvi+48);
}
void lcd_Gotoxy(unsigned char x,unsigned char y)//ham nhay dem vi tri x,y trong man hinh lcd
{
char position;
if (y==1)
{
position=0x80;
lcd_command(position|x);
}
else
{
position=0xC0;
lcd_command(position|x);
}
}
Comment