các pác ơi! pác nào có " sơ đồ mạch điều khiển đèn giao thông dùng vdk
AT89C52 " thì post lên cho tui tham khảo với. love all!
AT89C52 " thì post lên cho tui tham khảo với. love all!
/* Chuong Trinh den giao thong.Hien thi ra LCD.dung PIC16F877*/
#include "16f877.h"
#include "def_877a.h"
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use fast_io(b)
#use fast_io(d)
#define RS RD0
#define RW RD1
#define E RD2
#define LCD PORTB //LCD duoc dieu khien qua PORTB
int i=0;
const unsigned char key[]="15141312111009080706050403020100"; //Khai bao chuoi dem 15s cho den giao thong
void comwrt(void) //ghi lenh ra LCD
{
RS=0;
RW=0;
E=1;
E=0;
delay_ms(1);
}
void datawrt(void) //ghi data ra LCD
{
RS=1;
RW=0;
E=1;
E=0;
delay_ms(1);
}
void initLCD(void) //Khoi tao gia tri dau cho LCD
{
LCD=0x38;
comwrt();
LCD=0x0C;
comwrt();
LCD=0x06;
comwrt();
delay_ms(1);
}
void state1_light() //cac trang thang cua den giao thong
{
output_high(PIN_D3);
output_low(PIN_D4);
output_low(PIN_D5);
}
void state2_light()
{
output_low(PIN_D3);
output_high(PIN_D4);
output_low(PIN_D5);
}
void state3_light()
{
output_low(PIN_D3);
output_low(PIN_D4);
output_high(PIN_D5);
}
void LCD_count() //dem thoi gian 15s cho cac den xanh-Do
{
While(i<=30)
{
LCD=key[i];
datawrt();
i=i+1;
LCD=key[i];
datawrt();
i=i+1;
delay_ms(1000); //xuat lan luot 2 ki tu ra LCD
LCD=0x01; //xoa man hinh LCD
comwrt();
delay_ms(1000); //phai delay thi lenh xoa man hinh moi xoa het duoc man hinh(rat Quan Trong(
}
}
void wait_yellow_light() //Dem thoi gian 3s cho den vang
{
LCD='0';
datawrt();
LCD='3';
datawrt();
delay_ms(1000);
LCD=0x01;
comwrt();
delay_ms(1000);
LCD='0';
datawrt();
LCD='2';
datawrt();
delay_ms(1000);
LCD=0x01;
comwrt();
delay_ms(1000);
LCD='0';
datawrt();
LCD='1';
datawrt();
delay_ms(1000);
LCD=0x01;
comwrt();
delay_ms(1000);
LCD='0';
datawrt();
LCD='0';
datawrt();
delay_ms(1000);
LCD=0x01;
comwrt();
delay_ms(1000);
}
void main(void)
{
While(1)
{
set_tris_B(0);
PORTB=0;
set_tris_D(0);
PORTD=0;
initLCD(); //khoi tao LCD
state1_light(); //xanh-do
LCD_count();
delay_ms(1000);
i=0;
state2_light(); //vang-vang
wait_yellow_light();
delay_ms(1000);
i=0;
state3_light(); //do-xanh
LCD_count();
delay_ms(1000);
i=0;
}
}
Comment