发表于:2007/12/17 8:30:00
#0楼
以前都用汇编,C语言没弄过.
完全照书上的二个C语言例子,编译没通过.不知道错在哪里,请求帮助.谢谢
第一个程序:
#include<REG51.H>
#define uchar unsigned char
#define uint unsigned int
uchar code SEG7[10]={0xc0,0xf9,0xa4,
0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,}
void delay(uint k)
{
uint i,j
for(i=0;i<k;i++){
for(j=0;j<121;j++)
{;}}
}
void main(void)
{
uchar m=0,n=0
P0=SEG7[n]
P1=SEG7[m]
delay(3000)
P0=0xff
P1=0xff
P2=0xff
{
uchar m=8,x=6
P0=SEG7[n]
P1=SEG7[m]
P2=SEG7[x]
delay(3000)
P0=0xff
P1=0xff
P2=0xff
}
P0=SEG7[n]
P1=SEG7[m]
delay(3000)
while(1)
}
/*compiling no2c.c...
no2c.c(1): warning C315: unknown #directive 'includ'
NO2C.C(6): error C141: syntax error near 'void'
NO2C.C(7): error C141: syntax error near '{'
NO2C.C(9): error C141: syntax error near 'for'
NO2C.C(9): error C141: syntax error near '=', expected ')'
NO2C.C(9): error C129: missing ';' before '<'
no2c.c - 5 Error(s), 1 Warning(s).*/
第二个程序:
#include<reg51.h> /*item 1*/
void msec(unsigned int); /*item 2*/
void main( )
{
unsigned char array[10]
unsigned char i;
while(1) /*item 3*/
{
for(i=0;i<=9;i++) /*item 4*/
{
array[i]=P2=P0 /*单片机的C语言应用程序设计P89*/
msec(100)
}
}
}
void msec(unsigned int x){
unsigned char j;
while ((x--)! =0){
for(j=0,j<125;j++)
{;}
}
}
/*compiling no1c.c...
NO1C.C(6): error C141: syntax error near 'unsigned'
NO1C.C(11): error C202: 'p2': undefined identifier
NO1C.C(12): error C141: syntax error near 'msec'
NO1C.C(13): error C141: syntax error near '}'
NO1C.C(18): error C141: syntax error near '!'
NO1C.C(18): error C141: syntax error near '='
NO1C.C(18): error C141: syntax error near ')'
NO1C.C(19): error C141: syntax error near ')'
no1c.c - 8 Error(s), 0 Warning(s).*/
完全照书上的二个C语言例子,编译没通过.不知道错在哪里,请求帮助.谢谢
第一个程序:
#include<REG51.H>
#define uchar unsigned char
#define uint unsigned int
uchar code SEG7[10]={0xc0,0xf9,0xa4,
0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,}
void delay(uint k)
{
uint i,j
for(i=0;i<k;i++){
for(j=0;j<121;j++)
{;}}
}
void main(void)
{
uchar m=0,n=0
P0=SEG7[n]
P1=SEG7[m]
delay(3000)
P0=0xff
P1=0xff
P2=0xff
{
uchar m=8,x=6
P0=SEG7[n]
P1=SEG7[m]
P2=SEG7[x]
delay(3000)
P0=0xff
P1=0xff
P2=0xff
}
P0=SEG7[n]
P1=SEG7[m]
delay(3000)
while(1)
}
/*compiling no2c.c...
no2c.c(1): warning C315: unknown #directive 'includ'
NO2C.C(6): error C141: syntax error near 'void'
NO2C.C(7): error C141: syntax error near '{'
NO2C.C(9): error C141: syntax error near 'for'
NO2C.C(9): error C141: syntax error near '=', expected ')'
NO2C.C(9): error C129: missing ';' before '<'
no2c.c - 5 Error(s), 1 Warning(s).*/
第二个程序:
#include<reg51.h> /*item 1*/
void msec(unsigned int); /*item 2*/
void main( )
{
unsigned char array[10]
unsigned char i;
while(1) /*item 3*/
{
for(i=0;i<=9;i++) /*item 4*/
{
array[i]=P2=P0 /*单片机的C语言应用程序设计P89*/
msec(100)
}
}
}
void msec(unsigned int x){
unsigned char j;
while ((x--)! =0){
for(j=0,j<125;j++)
{;}
}
}
/*compiling no1c.c...
NO1C.C(6): error C141: syntax error near 'unsigned'
NO1C.C(11): error C202: 'p2': undefined identifier
NO1C.C(12): error C141: syntax error near 'msec'
NO1C.C(13): error C141: syntax error near '}'
NO1C.C(18): error C141: syntax error near '!'
NO1C.C(18): error C141: syntax error near '='
NO1C.C(18): error C141: syntax error near ')'
NO1C.C(19): error C141: syntax error near ')'
no1c.c - 8 Error(s), 0 Warning(s).*/