04-05-2010, 12:08 PM | #1 |
Nhập môn đệ tử
Tham gia ngày: May 2009
Bài gửi: 3
: |
Mạch đèn điều khiển tín hiệu giao thông!
Em làm đề tài điều khiển tín hiệu giao thông hiển thị số trên led 7 đoạn và đồng hồ thời gian thực trên LCD nhưng đến giai đoạn điều chỉnh số giây đèn xanh đèn đỏ thì ko làm đc ( Ai xem dùm em hàm quét bàn phím của em sai j mà sao lúc ấn nút nó ko tác dụng j cả (
Mọi người xem dùm hàm void change(); của em với nhé! //================================================== == Code:
#include <16f877a.h> #include <def_877a.h> #device *=16 ADC=8 //#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT #use delay(clock=20000000) #include "ds1307.c" #include <lcd_lib_4bit.c> #define SET PIN_E0 #define TANG PIN_E1 #define GIAM PIN_E2 #define START PIN_D0 void realtime(); void led7seg_do(); void led7seg_xanh(); Void Change(); int8 second; int16 temp1,temp2,temp3,temp4; //============================================================================ void main() { TRISA=0x00; TRISB=0x00; TRISC=0x00; TANG==GIAM==SET==START==1; //================Hien Thi Ban Dau===== init_ds1307(); lcd_init(); Printf(LCD_putchar,"Bai Tap Lon VXL"); LCD_putcmd(0xC4); Printf(LCD_putchar,"Nhom ITALY"); delay_ms(300); //====================================== change(); led7seg_do(); realtime(); } //============================================================================ void led7seg_do() { int i; // Khai Bao Bien Kieu int while(1) { if (temp2==0x00&&temp1==0x00) //Neu Dem Nguoc Ve 00 Thoat khoi ham while break; for(i=0;i<50;i++) { PORTB=0x05; // Hien Thi Chu So Hang Chuc PORTA=temp1; delay_us(190); PORTB=0x00; PORTA=0xFF; delay_us(10); //======================================= PORTB=0x0A; // Hien Thi Chu So Hang DonVi PORTA=temp2; delay_us(190); PORTB=0x00; PORTA=0xFF; delay_us(10); } //==================================== PORTB=0x00; // Tao Khoang Trong Giua 2 Lan Dem PORTA=0xFF; delay_ms(20); if (temp2==0x00) { temp1--; temp2=0x09; } else temp2--; } break; } //============================================================================= void led7seg_xanh() { int i; // Khai Bao Bien Kieu int while(1) { if (temp3==0x00&&temp4==0x00) //Neu Dem Nguoc Ve 00 Thoat khoi ham while break; for(i=0;i<50;i++) { PORTB=0x05; // Hien Thi Chu So Hang Chuc PORTA=temp3; delay_us(190); PORTB=0x00; PORTA=0xFF; delay_us(10); //======================================= PORTB=0x0A; // Hien Thi Chu So Hang DonVi PORTA=temp4; delay_us(190); PORTB=0x00; PORTA=0xFF; delay_us(10); } //==================================== PORTB=0x00; // Tao Khoang Trong Giua 2 Lan Dem PORTA=0xFF; delay_ms(20); if (temp4==0x00) { temp3--; temp3=0x09; } else temp4--; } break; } //============================================================================= Void Change() { LCD_putcmd(0x01); Printf(LCD_putchar,"Nhap Thoi Gian!"); delay_ms(100); LCD_putcmd(0xC3); Printf(LCD_putchar,"__Den Do__"); delay_ms(10); temp1=0x01; temp2=0x09; while(1) { if (START==0) {delay_us(10);break;} if (TANG==0) { delay_us(10); if (temp1==temp2==0x99) {temp1=temp2=0x00;break;} if (temp2==0x09) {temp1++;temp2=0x00;} //========= temp2++; PORTA=temp1; PORTB=0x01; delay_ms(10); PORTA=0xFF; PORTB=0x00; delay_us(10); //=============== PORTA=temp2; PORTB=0x02; delay_ms(10); PORTA=0xFF; PORTB=0x00; delay_us(10); } if (GIAM==0) { delay_us(10); if(temp1==temp2==0x00) {temp1=temp2=0x99;break;} if(temp2==0x00) {temp1--;temp2=0x09;} //========== temp2--; PORTA=temp1; PORTB=0x01; delay_ms(10); PORTA=0xFF; PORTB=0x00; delay_us(10); //=================== PORTA=temp2; PORTB=0x02; delay_ms(10); PORTA=0xFF; PORTB=0x00; delay_us(10); } //============================= PORTA=temp1; PORTB=0x01; delay_ms(10); PORTA=0xFF; PORTB=0x00; delay_us(10); PORTA=temp2; PORTB=0x02; delay_ms(10); PORTA=0xFF; PORTB=0x00; delay_us(10); } } //============================================================================== void realtime() { second=read_ds1307(0); write_ds1307(0,second&0x7F); write_ds1307(7,0x10); while(1) { if (SET==0){delay_ms(10);change();} else delay_ms(500); LCD_putcmd(0x01);//========Dua con tro ve dau dong 1====== Printf(LCD_putchar,"Time:"); second=read_ds1307(2); LCD_putchar(second/16 + 0x30); LCD_putchar(second%16 + 0x30); Printf(LCD_putchar,"-"); second=read_ds1307(1); LCD_putchar(second/16 + 0x30); LCD_putchar(second%16 + 0x30); Printf(LCD_putchar,"-"); second=read_ds1307(0); LCD_putchar(second/16 + 0x30); LCD_putchar(second%16 + 0x30); LCD_putcmd(0xC0); //===Dua Con Tro xuong dau dong 2======== Printf(LCD_putchar,"Date:"); second=read_ds1307(4); LCD_putchar(second/16 + 0x30); LCD_putchar(second%16 + 0x30); Printf(LCD_putchar,"-"); second=read_ds1307(5); LCD_putchar(second/16 + 0x30); LCD_putchar(second%16 + 0x30); Printf(LCD_putchar,"-"); second=read_ds1307(6); LCD_putchar(second/16 + 0x30); LCD_putchar(second%16 + 0x30); } } thay đổi nội dung bởi: demon52, 04-05-2010 lúc 04:15 PM. |
|
|