本范例主要由(main.c ,delay.h,delay.c,makefile)4个文件组成,sdcc的编译环境搭建参照:单片机成长之路(51基础篇) - 006 在Linux下搭建51单片机的开发烧写环境,废话不多,进入主题:
main.c(主函数)
1 #include "8051.h" 2 #include "delay.h" 3 #define uint unsigned int 4 #define uchar unsigned char 5 uchar tab[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; 6 7 void main(void){ 8 uchar i; 9 while(1){ 10 for(i=0;i<8;i++){ 11 P1 = tab[i]; 12 Delay(100); 13 } 14 } 15 }
delay.h(功能函数声明文件)
1 #ifndef DELAY_H 2 #define DELAY_H 3 #define uint unsigned int 4 #define uchar unsigned char 5 6 void Delay(uint xms); 7 8 #endif
delay.c(功能函数实体函数)
1 #include "delay.h" 2 3 void Delay(uint xms){ 4 uint i,j; 5 for(i=xms;i>0;i--) 6 for(j=110;j>0;j--); 7 }
makefile(make文件)
1 CC =sdcc 2 stc =sudo python /home/jikexianfeng/51-demo/.stcflash/stcflash.py 3 4 all : main.bin 5 6 #main.bin : main.hex 7 # ~/51-demo/.Hex2bin-2.5/hex2bin main.hex 8 9 main.bin : main.hex 10 objcopy -I ihex -O binary main.hex main.bin 11 $(stc) main.bin 12 13 main.hex : main.ihx 14 packihx main.ihx > main.hex 15 16 main.ihx : main.rel delay.rel 17 $(CC) main.rel delay.rel 18 19 main.rel : main.c delay.h 20 $(CC) -c main.c 21 22 delay.rel : delay.c 23 $(CC) -c delay.c 24 25 cleanall: 26 rm -rf *.lk *.bin *.asm *.lst *.mem *.rst *.lnk *.rel *.sym *.ihx *.hex *.map 27 clean: 28 rm -rf *.asm *.lst *.mem *.rst *.lnk *.rel *.sym *.ihx *.hex *.map
原文地址:https://www.cnblogs.com/jikexianfeng/p/9514979.html
时间: 2024-11-01 10:24:50