大佬們,我最近在學習寫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);
- }
- }
- }
復制代碼
|