大佬们,我最近在学习写STC8单片机的程序,但是我之前只学过89C51的,而且我不知道怎么规范化程序。官方的文档看起来也很晦涩,有没有大佬能够指导一下我的这个程序的移植问题~我是用89C51写的两个按键来控制数码管显示0-8,并且输出数字到P2口,向STC8移植并且规范化需要怎么来写呢?
- #include<reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit key=P0^0;
- sbit key1=P0^1;
- uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- void delay_lms(uint i){
- uchar t;
- while(i--)
- for(t=0;t<=150;t++);
- }
- void main(){
- uchar i=0;
- key=1;
- P1=0xc0;
- while(1){
- if(key==0){
- delay_lms(20);
- if(key==0){
- if(i<=6){i++;}
- else{i=7;}
-
- P1=tab[i];
- P2=i;
- if(i==7)i=7;
- }
- while(key==0);
- }
- if(key1==0){
- delay_lms(20);
- if(key1==0){
- if(i>=1){i--;}
- else{i=0;}
- P1=tab[i];
- P2=i;
- if(i==0)i=0;
- }
- while(key1==0);
- }
- }
- }
复制代码
|