|
- #include<reg52.h>
- #include"shuzu.h"
- #include<intrins.h>
- #define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};
- #define uchar unsigned char
- #define uint unsigned int
- #define ulong unsigned long
- typedef unsigned char uint8;
- typedef unsigned int uint16;
- sbit IRIN=P3^2;
- sbit MOSIO = P3^4;
- sbit R_CLK = P3^5;
- sbit S_CLK = P3^6;
- sbit P2_0 = P2^0;
- sbit P2_1 = P2^1;
- sbit P2_2 = P2^2;
- sbit P2_3 = P2^3;
- sbit rw=P2^5;
- sbit rs=P2^6;
- sbit e=P2^7;
- sbit led=P3^1;
- sbit dian=P2^4;
- sbit button=P3^0;
- sbit o=P3^7;
- uint8 key,num,k,biao,flag,fuhao;
- long a,b,c,d;
- uint8 dat1[]={1,2,3,0x2b-0x30, 4,5,6,0x2d-0x30, 7,8,9,0x2a-0x30, 0,0x01-0x30,0x3d-0x30,0x2b-0x30 };
- uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
- 0xf8,0x80,0x90 };
- uchar IRCOM[7];
- uchar m;
- void HC595SendData( uchar BT3, uchar BT2,uchar BT1,uchar BT0);
- void delay1ms();
- void delay(unsigned char x) ;
- void display();
- void delay1(int ms);
- void dianzhen(void);
- void HC595SendData( uchar BT3, uchar BT2,uchar BT1,uchar BT0);
- void lcdwrc(uint8 c);
- void lcdwrd(uint8 dat);
- void lcdinit();
- void keyscan();
- void ji();
- void LD();
- void main()
- {
- unsigned int a;
- dian=1;
- IRIN=1;
- IE=0x81;
- TCON=TCON|0x01;
- dian=0;
- while(1)
- {
- if(button==0)
- {
- delay(5);
- if(button==0)
- {
- while(button==0)
- a=1;
- }
- }
- if(a==1)
- {
- dian=~dian;
- a=0;
- }
- for(a=100;a>0;a--)
- {
- display();
- }
-
-
- }
- }
- void IR_IN() interrupt 0 using 0
- {
- unsigned char j,k,N=0;
- unsigned char q=0;
- EX0 = 0;
- delay(15);
- if (IRIN==1)
- {
- EX0 =1;
- return;
- }
-
- while (!IRIN)
- delay(1);
-
- for (j=0;j<4;j++)
- {
- for (k=0;k<8;k++)
- {
- while (IRIN)
- {delay(1);}
- while (!IRIN)
- delay(1);
- while (IRIN)
- {
- delay(1);
- N++;
- if (N>=30)
- {
- EX0=1;
- return;
- }
- }
- IRCOM[j]=IRCOM[j] >> 1;
- if(N>=8)
- {
- IRCOM[j] = IRCOM[j] | 0x80;
- }
- N=0;
- }
- }
-
- if(IRCOM[2]!=~IRCOM[3])
- {
- EX0=1;
- return;
- }
-
- IRCOM[5]=IRCOM[2] & 0x0F;
- IRCOM[6]=IRCOM[2] >> 4;
-
- if(IRCOM[5]>9)
- {
- IRCOM[5]=IRCOM[5]+0x37;
- }
- else
- IRCOM[5]=IRCOM[5]+0x30;
-
- if(IRCOM[6]>9)
- {
- IRCOM[6]=IRCOM[6]+0x37;
- }
- else
- IRCOM[6]=IRCOM[6]+0x30;
- q= (((IRCOM[6]&0x0f)<<4) + (IRCOM[5]&0x0f));
-
- switch(q)
- {
- case 0x16:m=0;break;
- case 0x03:m=1;break;
- case 0x18:m=2;LD();break;
- case 0x55:m=3;break;
- case 0x08:m=4;break;
- case 0x13:m=5;ji();break;
- case 0x51:m=6;break;
- case 0x42:m=7;break;
- case 0x52:m=8;dianzhen();break;
- case 0x41:m=9;break;
-
- default :break;
- }
- EX0 = 1;
- }
- void delay(unsigned char x)
- {
- unsigned char i;
- while(x--)
- {
- for (i = 0; i<13; i++) {}
- }
- }
- void display()
- {
-
- P0=table[m];
- P2_3 = 0;
- delay(5);
- P2_3 = 1;
-
- }
- void delay1(int ms)
- {
- unsigned char y;
- while(ms--)
- {
- for(y = 0; y<250; y++)
- {
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- }
- }
- }
- //************************************************************
- void delay1ms()
- {
- unsigned int i;
- for(i=8024;i>0;i--);
- }
- void dianzhen(void)
- {
- int k, j, ms,y;
-
- uchar *p[] =
- { tab1, tab2, tab3, tab4, tab5, tab6, tab7, tab8,
- tab9, tab10, tab11, tab12, tab13, tab14, tab15, tab16,tab17,};
-
- for(y=170;y>0;y--)
- {
- for(ms = 3; ms > 0; ms--)
- {
- for(k = 0; k < 17; k++)
- {
- HC595SendData(~tab0[2*k],~tab0[2*k + 1],(*(p[0] + 2*(k+j) + 1)),(*(p[0] + 2*(k+j) )));
- }
-
- HC595SendData(0xff,0xff,0,0);
- }
-
-
- j++;
- if(j == (15*15) )
- {
- j = 0;
- }
- }
- }
- void HC595SendData( uchar BT3, uchar BT2,uchar BT1,uchar BT0)
- {
- uchar i;
-
- for(i=0;i<8;i++)
- {
- MOSIO = BT3 >> 7 ;
- BT3 <<= 1;
- S_CLK = 0;
- S_CLK = 1;
- }
- for(i=0;i<8;i++)
- {
- MOSIO = BT2 >>7;
- BT2 <<= 1;
- S_CLK = 0;
- S_CLK = 1;
- }
- for(i=0;i<8;i++)
- {
- MOSIO = BT1 >> 7;
- BT1 <<= 1;
- S_CLK = 0;
- S_CLK = 1;
- }
- for(i=0;i<8;i++)
- {
- MOSIO = BT0 >> 7;
- BT0 <<= 1;
- S_CLK = 0;
- S_CLK = 1;
- }
-
- R_CLK = 0;
- R_CLK = 1;
- R_CLK = 0;
- }
- void lcdwrc(uint8 c)
- {
- delay(1000);
- rs=0;
- rw=0;
- e=0;
- P0=c;
- e=1;
- delay(1000);
- e=0;
- }
- void lcdwrd(uint8 dat)
- {
- delay(1000);
- rs=1;
- rw=0;
- e=0;
- P0=dat;
- e=1;
- delay(1000);
- e=0;
- rs=0;
- }
- void lcdinit()
- {
- delay(1500);
- lcdwrc(0x38);
- delay(500);
- lcdwrc(0x38);
- delay(500);
- lcdwrc(0x38);
- delay(500);
- lcdwrc(0x38);
- lcdwrc(0x08);
- lcdwrc(0x01);
- lcdwrc(0x06);
- lcdwrc(0x0c);
- key=0;
- num=0;
- flag=0;
- fuhao=0;
- a=0;
- b=0;
- c=0;
- d=0;
- biao=0;
- led=0;
- }
- void keyscan()
- {
- P1=0xfe;
- if(P1!=0xfe)
- {
复制代码
未完
|
|