数码管模块化编程
#include "config.h"
unsigned char code d[8] = {2,0,2,2,0,2,2,5}
void Display_SMG(unsigned char pos,dat)
{
Y6;
P0 = 0x01 << pos;
Y7;
P0 = dat;
}
void Display()
{
unsigned char i = 0;
for(i=0;i<8;i++)
{
Display_SMG(i,d[i]);
}
}
void Display_data(unsigned char d0,d1,d2,d3,d4,d5,d6,d7)
{
d1=d[1];
d2=d[2];
d3=d[3];
d4=d[4];
d5=d[5];
d6=d[6];
d7=d[7];
}
void main()
{
while(1)
{
Display();
}
}
“config.h"
#ifndef _CONFIG_H
#define _CONFIG_H
#include <STC15F2K60S2.H>
#include <intrins.h>
#define Y4 P2 = (P2&0x1f)|0x80;
#define Y5 P2 = (P2&0x1f)|0xa0;
#define Y6 P2 = (P2&0x1f)|0xc0;
#define Y7 P2 = (P2&0x1f)|0xe0;
void Delay10ms(); //@12.000MHz
void Delay500ms(); //@12.000MHz
void Delay1ms();
#endif
smg_ca.c(5): error C141: syntax error near 'void', expected ';'
smg_ca.c(6): error C141: syntax error near '{', expected ';'
smg_ca.c(7): error C231: 'P2': redefinition
smg_ca.c(7): error C247: non-address/-constant initializer
smg_ca.c(7): error C231: 'P2': redefinition
smg_ca.c(7): error C141: syntax error near ';', expected 'hdata'
smg_ca.c(8): error C231: 'P0': redefinition
smg_ca.c(8): error C202: 'pos': undefined identifier
smg_ca.c(8): error C231: 'P0': redefinition
smg_ca.c(9): error C279: 'P2': multiple initialization
smg_ca.c(9): error C231: 'P2': redefinition
smg_ca.c(9): error C247: non-address/-constant initializer
smg_ca.c(9): error C231: 'P2': redefinition
smg_ca.c(9): error C141: syntax error near ';', expected 'hdata'
smg_ca.c(10): error C279: 'P0': multiple initialization
smg_ca.c(10): error C231: 'P0': redefinition
smg_ca.c(10): error C202: 'dat': undefined identifier
smg_ca.c(10): error C231: 'P0': redefinition
smg_ca.c(11): error C141: syntax error near '}', expected 'hdata'
smg_ca.c(19): error C141: syntax error near '}', expected ';'