Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

error related to serial code for interfacing 8052

Status
Not open for further replies.

sgtom

Junior Member level 1
Junior Member level 1
Joined
Mar 14, 2011
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,492
when i try interfacing my stopwatch using 8052 with the PC this is the error we get:
Build target 'Target 1'
compiling microcontroller programming.c...
MICROCONTROLLER PROGRAMMING.C(123): error C267: 'serial': requires ANSI-style prototype
Target not created

if u can pls help me the code:

that is the original code:


#include<reg51.h>
#define msec 1
unsigned int sec1,sec2;
int sec1_1,sec1_2,sec2_1,sec2_2;

unsigned int
digi_val[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10};
sbit dig_ctrl_1=P1^0;
sbit dig_ctrl_2=P1^1;
sbit dig_ctrl_3=P1^2;
sbit dig_ctrl_4=P1^3;
sbit start_pin = P1^4;
sbit stop_pin = P1^5;
sbit reset_pin = P1^6;
int s,t;

void mplex_delay(unsigned int time)
{
int i,j;
for (i=0;i<=time;i++)
for(j=0;j<=50;j++);
}

void digi_out(unsigned int current_num)
{
P2=digi_val[current_num];
mplex_delay(msec);
}

void display(unsigned int dig1,unsigned int dig2)
{
sec1_2=dig1%10;
sec1_1=dig1/10;
sec2_2=dig2%10;
sec2_1=dig2/10;
TMOD=0x01;
TL0=0xFF;
TH0=0xDB;
TR0=1;
while(TF0==0)
{
dig_ctrl_1 = 1;
dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_4 = 0;
digi_out(sec1_1);
dig_ctrl_2 = 1;
dig_ctrl_1 = dig_ctrl_3 = dig_ctrl_4 = 0;
digi_out(sec1_2);
dig_ctrl_3 = 1;
dig_ctrl_2 = dig_ctrl_1 = dig_ctrl_4 = 0;
digi_out(sec2_1);
dig_ctrl_4 = 1;
dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_1 = 0;
digi_out(sec2_2);
}
TR0=0;
TF0=0;
}
void serial()
{
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
while (1)
{
SBUF = sec1;
while(TI==0);
TI = 0;
}
}


void serial1_1()
{
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
while (1)
{
SBUF = sec2;
while(TI==0);
TI = 0;
}
}







void main()
{
while(1)
{
start:
start_pin = 1;
stop_pin = 1;
reset_pin = 1;
dig_ctrl_1 = 0;
dig_ctrl_2 = 0;
dig_ctrl_3 = 0;
dig_ctrl_4 = 0;
P2 = 0xFF;
s = t = 0;
while(start_pin == 1)
{
display(0,0);
}

stopwatch:
for (sec1=s;sec1<=99;sec1++)
{
if (stop_pin == 0 )
break;
for (sec2=t;sec2<=99; sec2++)
{
if (stop_pin == 0 )
break;
t=0;
display(sec1,sec2);
serial(sec1);
serial1_1(sec2);
}
}
stop_pin = 1;
s = sec1;
t = sec2;


while ( start_pin != 0 && reset_pin != 0 )
{
display(sec1,sec2);
}

if (start_pin == 0)
{
goto stopwatch;
}
else
{
if (reset_pin == 0 )
{
s = t = 0;
goto start;
}
}
}
}
 

where are the function prototypes defined?????

---------- Post added at 07:06 ---------- Previous post was at 07:04 ----------

in this line
digi_val[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x1 0};
for the last character 0x10 is there a space between 1 and 0... post your errors completely taking snapshot please...

---------- Post added at 07:07 ---------- Previous post was at 07:06 ----------

which is the controller part number you are using.. you are using reg51.h but you tell you use 8052?????
 

i have printscreened th excact error window, its still that one error.

using AT89s52
 

Attachments

  • errors.png
    errors.png
    161.2 KB · Views: 147

where is the function prototype for function serial????

---------- Post added at 07:44 ---------- Previous post was at 07:37 ----------

void serial()
{
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
while (1)
{
SBUF = sec1;
while(TI==0);
TI = 0;
}
}

serial(sec1);
serial1_1(sec2);

you are passing arguements to serial function as sec2 cut in the above serial function there is no arguements passed even in serial1_1 function also same problem. you write function without arguements but when calling a function you pass arguements...
 
  • Like
Reactions: sgtom

    sgtom

    Points: 2
    Helpful Answer Positive Rating
if u can pls let me know what is function prototype?, cause i am not understanding what r u trying to say, or r u talking abt the void function?

Thanks
 

see my above post

when you call serial function you call with arguement serial(sec1)....... but your function serial which is written for serial comm initialization does not have any parameters / arguements.

same way with serial1_1... you pass arguments but in the function it is not having any arguments...
 
  • Like
Reactions: sgtom

    sgtom

    Points: 2
    Helpful Answer Positive Rating
So is it related to void serial(), or how do u exactly call an arguement while calling the function, if u can pls ellaborate with an example.

Thanks
 

see this example1:

function prototype : void lcd_cmdwrt(unsigned char cmd);

calling this function in main is like this lcd_cmdwrt(0x01);

called function will be written like this ..........

void lcd_cmdwrt(unsigned char cmd)
{
RS=0;
EN=1;
delay(1);
EN=0;
}


e.g.2
prototype: void lcd_datawrt(unsigned char *);

calling function lcd_datawrt("Hello");

called function: void lcd_datawrt(unsigned char *str)
{
while(*str)
{
dat(*str);
str++;
}
}

---------- Post added at 08:21 ---------- Previous post was at 08:18 ----------

you could well look into C programming aspects before doing programming as, I feel you are not in touch with programming concepts....
 

So can we put void serial (void), instead of void serial(), is that what u mean exactly?, pls let me know asap.

Thanks.
 

now we have used :
void serial(unsigned int sec1)
so basically it compiled but when we interface, it shows smiley faces, hearts, and clubs and random characters, so how do we read the time out of it.

this is our final main code that complied:

#include<reg51.h>
#define msec 1
unsigned int sec1,sec2;
int sec1_1,sec1_2,sec2_1,sec2_2;

unsigned int digi_val[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10};
sbit dig_ctrl_1=P1^0;
sbit dig_ctrl_2=P1^1;
sbit dig_ctrl_3=P1^2;
sbit dig_ctrl_4=P1^3;
sbit start_pin = P1^4;
sbit stop_pin = P1^5;
sbit reset_pin = P1^6;
int s,t;

void mplex_delay(unsigned int time)
{
int i,j;
for (i=0;i<=time;i++)
for(j=0;j<=50;j++);
}

void digi_out(unsigned int current_num)
{
P2=digi_val[current_num];
mplex_delay(msec);
}

void display(unsigned int dig1,unsigned int dig2)
{
sec1_2=dig1%10;
sec1_1=dig1/10;
sec2_2=dig2%10;
sec2_1=dig2/10;
TMOD=0x01;
TL0=0xFF;
TH0=0xDB;
TR0=1;
while(TF0==0)
{
dig_ctrl_1 = 1;
dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_4 = 0;
digi_out(sec1_1);
dig_ctrl_2 = 1;
dig_ctrl_1 = dig_ctrl_3 = dig_ctrl_4 = 0;
digi_out(sec1_2);
dig_ctrl_3 = 1;
dig_ctrl_2 = dig_ctrl_1 = dig_ctrl_4 = 0;
digi_out(sec2_1);
dig_ctrl_4 = 1;
dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_1 = 0;
digi_out(sec2_2);
}
TR0=0;
TF0=0;
}
void serial(unsigned int sec1)
{
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
while (1)
{
SBUF = sec1;
while(TI==0);
TI = 0;
}
}


void serial1_1(unsigned int sec2)
{
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
while (1)
{
SBUF = sec2;
while(TI==0);
TI = 0;
}
}



void main()
{
while(1)
{
start:
start_pin = 1;
stop_pin = 1;
reset_pin = 1;
dig_ctrl_1 = 0;
dig_ctrl_2 = 0;
dig_ctrl_3 = 0;
dig_ctrl_4 = 0;
P2 = 0xFF;
s = t = 0;
while(start_pin == 1)
{
display(0,0);
}

stopwatch:
for (sec1=s;sec1<=99;sec1++)
{
if (stop_pin == 0 )
break;
for (sec2=t;sec2<=99; sec2++)
{
if (stop_pin == 0 )
break;
t=0;
display(sec1,sec2);
}
}
stop_pin = 1;
s = sec1;
t = sec2;

while (stop_pin = 1 && reset_pin != 0 )
{
serial(sec1);
serial1_1(sec2);
}


while ( start_pin != 0 && reset_pin != 0 )
{
display(sec1,sec2);
}

if (start_pin == 0)
{
goto stopwatch;
}
else
{
if (reset_pin == 0 )
{
s = t = 0;
goto start;
}
}
}
}
 

did you see it first in the keil simulation window or hyperterminal.... if it is hyperterminal then check the baudrate settings........ wheere are you seeing the output.....
 

So is the code which we r using rite?, as in wat should we do?, we r using hyper terminal of the PC which we connect our serial circuit to, and yeah we r given an option to select/set the baud rate, which we set it to 9600, so what else can we do?

Thank you.
 

Can u Plzz tell me how to use the simulation window in keil...i just cant find it..srry to bother u...much appreciated..
 

you compile the code and then start debugging. Go to view and select serial window1 and come back to program and give run command.......

---------- Post added at 21:59 ---------- Previous post was at 21:55 ----------

then go to peripherals and open Port1
Make p1.5 and 1.6 =0 by unchecking them . keep the program running.....

right click on serial window and change the mode to hex.. after some time stop running the program and see the output in the window....

it is printing 00 00 00....
 

This is my altered code. With no errors and warnings,

However I am not able to view any values in the serial window.

PLEASE HELP!

#include<reg51.h>
#define msec 1
float sec1,sec2;
int sec1_1,sec1_2,sec2_1,sec2_2;


unsigned int digi_val[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10};
sbit dig_ctrl_1=P1^0;
sbit dig_ctrl_2=P1^1;
sbit dig_ctrl_3=P1^2;
sbit dig_ctrl_4=P1^3;
sbit start_pin = P1^4;
sbit stop_pin = P1^5;
sbit reset_pin = P1^6;
int s,t;

void mplex_delay(unsigned int time)
{
int i,j;
for (i=0;i<=time;i++)
for(j=0;j<=5;j++);
}

void digi_out(unsigned int current_num)
{
P2=digi_val[current_num];
mplex_delay(msec);
}

void display(unsigned int dig1,unsigned int dig2)
{
sec1_2=dig1%10;
sec1_1=dig1/10;
sec2_2=dig2%10;
sec2_1=dig2/10;
TMOD=0x01;
TL0=0xFF;
TH0=0xDB;
TR0=1;
while(TF0==0)
{
dig_ctrl_1 = 1;
dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_4 = 0;
digi_out(sec1_1);
dig_ctrl_2 = 1;
dig_ctrl_1 = dig_ctrl_3 = dig_ctrl_4 = 0;
digi_out(sec1_2);
dig_ctrl_3 = 1;
dig_ctrl_2 = dig_ctrl_1 = dig_ctrl_4 = 0;
digi_out(sec2_1);
dig_ctrl_4 = 1;
dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_1 = 0;
digi_out(sec2_2);
}

TR0=0;
TF0=0;
}

void serial (unsigned int sec1)
{
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
while (1)
{
SBUF = sec1;
while (TI == 0);
TI = 0;
}
}

void main()
{
while(1)
{
start:
start_pin = 1;
stop_pin = 1;
reset_pin = 1;
dig_ctrl_1 = 0;
dig_ctrl_2 = 0;
dig_ctrl_3 = 0;
dig_ctrl_4 = 0;
P2 = 0xFF;
s = t = 0;
while(start_pin == 1)
{
display(0,0);
}

stopwatch:
for (sec1=s;sec1<=99;sec1++)
{
if (stop_pin == 0 )
break;
for (sec2=t;sec2<=99; sec2++)
{
if (stop_pin == 0 )
break;
t=0;
display(sec1,sec2);
}
}
stop_pin = 1;
s = sec1;
t = sec2;
sec1 = sec1/10;
while ( start_pin != 0 && reset_pin != 0 )
{
display(sec1,sec2);
}

while (stop_pin != 0 && reset_pin != 1)
{
serial(sec1);
serial(sec2);

if (reset_pin == 0)
{
s = t = 0;
goto start;
}
}

if (start_pin == 0)
{
goto stopwatch;
}
else
{
if (reset_pin == 0 )
{
s = t = 0;
goto start;
}
}
}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top