问题是这样的,我在学习51单片机的时候看到老师讲了模块化,所以自己写了一个,然后结构图在上面
- #include <8052.h>
- #include "../Sleep.h"
- #include "../nixie.h"
- void main() {
- // P2_4=0;
- // P2_3=0;
- // P2_2=1;
- P2 = 0x00;
-
- while (1) {
- Nixie(1, 4);
- Nixie(2, 6);
- // Sleep(3);
- // P2_2 = 0;
- }
- }
复制代码 在写完这个代码之后使用sdcc main.c发出警告
- qin@QindeMacBook-Pro 08 动态数码管显示 % sdcc main.c
- ?ASlink-Warning-Undefined Global '_Nixie' referenced by module 'main'
- ?ASlink-Warning-Undefined Global '_Nixie_PARM_2' referenced by module 'main'
复制代码
但还是可以生成文件的,然后使用stcgal -P stc89 -p /dev/tty.wchusbserial11140 main.ihx
编译后,未能实现正常效果
以下为用到的文件
nixie.c
- #include "nixie.h"
- #include <8052.h>
- char num[18] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71, 0x00};
- void Nixie(unsigned char weizhi, unsigned char number) {
- switch (weizhi)
- {
- case 1:
- P2_4=1;P2_3=1;P2_2=1;
- break;
- case 2:
- P2_4=1;P2_3=1;P2_2=0;
- break;
- case 3:
- P2_4=1;P2_3=0;P2_2=1;
- break;
- case 4:
- P2_4=1;P2_3=0;P2_2=0;
- break;
- case 5:
- P2_4=0;P2_3=1;P2_2=1;
- break;
- case 6:
- P2_4=0;P2_3=1;P2_2=0;
- break;
- case 7:
- P2_4=0;P2_3=0;P2_2=1;
- break;
- case 8:
- P2_4=0;P2_3=0;P2_2=0;
- break;
- default:
- break;
- }
-
- switch (number)
- {
- case 0:
- P0=num[0];
- break;
- case 1:
- P0=num[1];
- break;
- case 2:
- P0=num[2];
- break;
- case 3:
- P0=num[3];
- break;
- case 4:
- P0=num[4];
- break;
- case 5:
- P0=num[5];
- break;
- case 6:
- P0=num[6];
- break;
- case 7:
- P0=num[7];
- break;
- case 8:
- P0=num[8];
- break;
- case 9:
- P0=num[9];
- break;
- case 'A':
- P0=num[10];
- break;
- case 'B':
- P0=num[11];
- break;
- case 'C':
- P0=num[12];
- break;
- case 'D':
- P0=num[13];
- break;
- case 'E':
- P0=num[14];
- break;
- case 'F':
- P0=num[15];
- case ' ':
- P0=num[16];
- default:
- break;
- }
- Sleep(2);
- P0 = 0x00;
- }
复制代码
nixie.h
- #ifndef __NIXIE_H__
- #define __NIXIE_H__
- void Nixie(unsigned char weizhi, unsigned char number);
- #endif
复制代码
Sleep.c- void Sleep(unsigned int xms)
- {
- unsigned char i, j;
- while (xms)
- {
- i = 2;
- j = 199;
- do {
- while (--j);
- } while(--i);
- xms--;
- }
- // _nop_();
- }
复制代码
Sleep.h
- #ifndef __SLEEP_H__
- #define __SLEEP_H_
- void Sleep(unsigned int xms);
- #endif
复制代码
系统是Macos,在这里请教一下各位大佬
|