请大家帮我看看这个程序有什么问题。用1602显示解码遥控器。我运行的结果是显示乱码。
- #include
- #define uchar unsigned char
- #define uint unsigned int
- uchar irtime;
- uchar startflag;
- uchar irdata[33];
- uchar bitnum;
- uchar irreceok;
- uchar ircode[4];
- uchar irprosok;
- uchar disp[8];
- //++++++++++++++++++++++++++++++++++++++++++++++++++
- //1602
- ***it rs=P2^6;
- ***it rw=P2^5;
- ***it e=P2^7;
- char i,j,k;
- void delay(char a)
- {
- for(k=0;k
- for(i=0;i<=110;i++);
- }
- void write(char r,char com)
- {
- rw=0;
- rs=r;
- P0=com;
- delay(1);
- e=1;
- delay(1);
- e=0;
- }
- void init()
- {
- e=0;
- write(0,0x38);
- write(0,0x0c);
- write(0,0x06);
- write(0,0x01);
- }//+++++++++++++++++++++++++++++++++++
- void timer0init(void)
- {
- TMOD=0x02;
- TH0=0x00;
- TL0=0x00;
- ET0=1;
- EA=1;
- TR0=1;
- }
- void int0init(void)
- {
- IT0=1;
- EX0=1;
- EA=1;
- }
- void irwork(void)
- {
- char i;
- disp[0]=ircode[0]/16;
- disp[1]=ircode[0]%16;
- disp[2]=ircode[1]/16;
- disp[3]=ircode[1]%16;
- disp[4]=ircode[2]/16;
- disp[5]=ircode[2]%16;
- disp[6]=ircode[3]/16;
- disp[7]=ircode[3]%16;
- for(i=0;i<8;i++)
- {
- if(disp>9)
- disp=disp+0x37;//实验
- else
- disp=disp+0x30;
- }
- }
- void irpros(void) //0x1c
- {
- uchar k,i,j;
- uchar value;
- k=1;
- for(j=0;j<4;j++)
- {
- for(i=0;i<8;i++)
- {
- value=value>>1; //7
- if(irdata[k]>6) //8
- {
- value=value | 0x80;
- }
- k++;
- }
- ircode[j]=value;
- }
- irprosok=1;
- }
- void main()
- {
- char i;
- timer0init();
- int0init();
- if(irreceok)
- {
- irpros();
- irreceok=0;
- }
- if(irprosok)
- {
- irwork();
- irprosok=0;
- }
- init();
- write(0,0x80);
- for(i=0;i<8;i++)
- {
- write(1,disp);
- }
- while(1);
- }
- void timer0 () interrupt 1
- {
- irtime++; //255
- }
- void int0 () interrupt 0
- {
- if(startflag)
- {
- if(irtime>52) //检测引导码
- {
- bitnum=0;
- }
- irdata[bitnum]=irtime;
- irtime=0;
- bitnum++;
- if(bitnum==33)
- {
- bitnum=0;
- irreceok=1;
- }
- }
- else
- {
- startflag=1;
- irtime=0;
- }
- }
采集
采集