|
- /*************** writer:shopping.w ******************/
- #include <reg52.h>//頭文件
- #define uint unsigned int//宏定義無符號(hào)整型變量
- #define uchar unsigned char//宏定義無符號(hào)字符型變量
- uchar Receive_Buffer[101];//定義一個(gè)接收緩存數(shù)組
- uchar Buf_Index = 0;//定義一個(gè)無符號(hào)字符型變量
- uchar code DSY_CODE[]=
- {
- 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00
- };//共陰極數(shù)碼管編碼值
- void Delay(uint x)//延時(shí)函數(shù)
- {
- uchar i;
- while(x--)
- {
- for(i=0;i<120;i++);
- }
- }
- void main()//主函數(shù)
- {
- uchar i;//定義一個(gè)無符號(hào)字符型變量
- P0 = 0x00;//初始化P0口,賦值為0,輸出低電平
- Receive_Buffer[0]=i;//初始化數(shù)組0的值
- SCON = 0x50;//單片機(jī)寄存器設(shè)置
- TMOD = 0x20;//
- PCON = 0x00;//
- TH1 = 0xfd;//計(jì)數(shù)器初始化高八位
- TL1 = 0xfd;//低八位
- EA = 1;//開總中斷
- EX0 = 1;//開外部中斷
- IT0 = 1;//啟動(dòng)定時(shí)器中斷
- ES = 1;//啟動(dòng)外部中斷
- IP = 0x01;
- TR1 = 1;//啟動(dòng)定時(shí)器1
- while(1)//循環(huán)
- {
- for(i=0;i<100;i++)
- {
- if(Receive_Buffer[i]==-1)
- break;
- P0 = DSY_CODE[Receive_Buffer[i]];
- Delay(200);
- }
- Delay(200);
- }
- }
- void Serial_INT() interrupt 4
- {
- uchar c;
- if(RI==0)
- return;
- ES = 0;
- RI = 0;
- c = SBUF;
- if(c>='0' && c<='9')
- {
- Receive_Buffer[Buf_Index]=c-'0';
- Receive_Buffer[Buf_Index+1]=-1;
- Buf_Index = (Buf_Index+1)%100;
- }
- ES = 1;
- }
- void EX_INT0() interrupt 0
- {
- uchar *s = ("Receiving From 8051...\r\n");
- uchar i = 0;
- while(s[i]!='\0')
- {
- SBUF = s[i];
- while(TI == 0);
- TI = 0;
- i++;
- }
- }
復(fù)制代碼 |
|