cuối cùng cũng hoàn thành
mạch PCB (vẽ hơi xấu)
mạch PCB (vẽ hơi xấu)
Code:
#include <regx51.h> //su dung thach anh 12mhz //Ngo Hung Cuong //kidteam@gmail.com //0989696971 - 0915696971 #define signal P3_2 #define led P2_7 unsigned char newkey; //============================================ void delay(void);//chuong trinh con delay 750 void EX0_ISR(void); void init(void);//chuong trinh con khoi tao //============================================ void main(void) { init(); //TMOD=1; while(1) { //if(!signal) //EX0_ISR(); } } //cac chuong trinh con duoc cai dat o day //============================================ void delay(void) { //su dung timer 0 luon TH0=0xfd;//-740 TL0=0x1c;//-740 TR0=1; while(!TF0); TR0=0; TF0=0; //tre khoang 750us } //============================================ void init(void) { //khoi tao cho timer va ngat ngoai //cac che do can thiet TMOD=1;//timer 0 che do 1 EX0=1; IT0=1; EA=1; } //============================================ void EX0_ISR(void) interrupt 0 { unsigned char i,j; unsigned char cmd; cmd=0; for(i=0;i<3;++i) { //kiem tra xem co phai la nhieu hay khong delay(); if(signal) return; } //doi tiep cho tin hieu len cao while(!signal); //sau 3 lan delay ma van o muc thap chung to khong phai la nhieu //bat dau thu tin hieu thoi nao //thong nhat la chi thu 7 bit ma lenh thoi //khong thu 5 bit dia chi //cho cho tin hieu len cao //phai cho vao vong lap //tin hieu dang o muc cao for(i=0;i<7;++i) { cmd>>=1; while(signal); delay(); //kiem tra bit if(!signal)//bit 0 { //bit 1 cmd|=0x80; while(!signal); } } cmd>>=1; if(cmd==21) led=!led; for(i=0;i<100;++i) for(j=0;j<10;++j) delay(); }
Comment