|
#include<reg52.h> //52單片機(jī)頭文件 #define uint unsigned int //宏定義 #define uchar unsigned char //宏定義 sbit P31=P3^1; //串口輸出 sbit P34=P3^4; //方波輸出 sbit P14=P1^4; //按建設(shè)置 sbit P15=P1^5; sbit P16=P1^6; sbit P17=P1^7; void init(); char getkey() { if(!P14)return 1; if(!P15)return 2; if(!P16)return 3; if(!P17)return 4; return 0; } void UartSend(unsigned char buf) { SBUF=buf; while(!TI); TI = 0; } void main() //主函數(shù) { char key; init(); do{ key=getkey(); if(key==1)UartSend(1);//0 if(key==2)UartSend(2);//exit if(key==3)UartSend(3);//+ if(key==4)UartSend(4);//- } while(1); } void timer0() interrupt 1 { TH0=0xFF; TL0=0xE6; P34=~P34; } void init() { //方波產(chǎn)生 TMOD|=0x01; //設(shè)置定時器0為工作方式1 TH0=0xFF; //產(chǎn)生38k方波 TL0=0xE6; EA=1; //全局中斷允許 ET0 = 1; //打開定時器0中斷 TR0=1; //啟動定時器0 //串口設(shè)置 TMOD|=0x20; //T1定時器工作方式2 TH1=0xfd; //裝初值 TL1=0xfd; //裝初值 TR1=1; //啟動定時器1 SM0=0; //設(shè)定串口工作方式1 SM1=1; //同上 } |
|