求高手幫我看看,有什么問題。由P1口低4位送入BCD碼,P2、P3輸出控制15臺電機。采用STC15W408。單片機程序如下
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar temp,key;
- /*uchar code table[]={
- 0xfe,0xfd,0xfb,0xf7,
- 0xef,0xdf,0xbf,0x7f,0xff}; */
- void delayms(uint xms)
- {
- uint i,j;
- for(i=xms;i>0;i--)
- for(j=110;j>0;j--);
- }
- void main()
- {
- P3=0xff;
- P2=0xff;
- // P1=0xff;
- while(1)
- {
-
- P3=0xff;
- P2=0xff;
- // P1=0xff;
- temp=P1;
- if(temp!=0xff)
- {
- delayms(20);
- temp=P1;
- if(temp!=0xff)
- {
- temp=P1;
- switch(temp)
- {
- case 0x01:
- P3=0xfe;
- break;
- case 0x02:
- P3=0xfd;
- break;
- case 0x03:
- P3=0xfb;
- break;
- case 0x04:
- P3=0xf7;
- break;
- case 0x05:
- P3=0xef;
- break;
- case 0x06:
- P3=0xdf;
- break;
- case 0x07:
- P3=0xbf;
- break;
- case 0x08:
- P3=0x7f;
- break;
- case 0x09:
- P2=0xfe;
- break;
- case 0x0a:
- P2=0xfd;
- break;
- case 0x0b:
- P2=0xfb;
- break;
- case 0x0c:
- P2=0xf7;
- break;
- case 0x0d:
- P2=0xef;
- break;
- case 0x0e:
- P2=0xdf;
- break;
- case 0x0f:
- P2=0xbf;
- break;
- }
- while(temp!=0xff)
- {
- temp=P1;
- }
- P2=0xff;
- P3=0xff;
- }
-
- }
- }
- }
復制代碼
|