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.

issues regarding SOFTWARE UART of 8051

Status
Not open for further replies.

sanket.joshi

Member level 3
Joined
Jun 27, 2013
Messages
65
Helped
8
Reputation
16
Reaction score
8
Trophy points
8
Location
Mumbai,India
Activity points
386
i have code for software uart which i got from following link
https://www.8051projects.net/forum-t11828.html

but while building project i m getting 3 warnings..
changes that i made to program are
1.commented these statements
PUBLIC putc
PUBLIC getc
i have commented these two because EXTERN & PUBLIC can't be together...

2.also removed underscore(_) symbol before each putc

the warning m getting are

*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
SYMBOL: _PUTC
MODULE: sw.obj (SW)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
SYMBOL: ?C_STARTUP
MODULE: sw.obj (SW)
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
SYMBOL: _PUTC
MODULE: sw.obj (SW)
ADDRESS: 0844H

please help me out as early as possible....
 

Post the code here.

code :


Code:
#include <regx51.h>

#include <stdio.h>


void putc(unsigned char);
void putc(unsigned char);


#pragma ASM

?SU?PUTC SEGMENT CODE
?SU?GETC SEGMENT CODE

PUBLIC _putc
PUBLIC getc

txd_pin EQU     P2.1            ;Transmit on this pin
rxd_pin EQU     P2.0            ;Receive on this pin

;Formula to calculate the bit time delay constant
 ;This constant is calculated as: (((crystal/baud)/12) - 5) / 2
 ;crystal is the frequency of crystal in Hz
 ;baud is required baudrate
 ;Please try to keep baudrate below 9600
 ;to get best results :)

BITTIM  EQU     45;             (((11059200/9600)/12) - 5) / 2

;--------------------------------------------
 ;To send data serially
 ;For C programs
 ;Protype definition:
 ;               void putc(unsigned char);
 ;Usage:
 ;               putc(data);
 ;Return:
 ;               This function returns nothing
 ;
 ;For Assembly Programs:
 ;
 ;Usage:
 ;       data to be send has to be moved to R7
 ;       for example:
 ;               mov R7,#'a'
 ;               lcall _putc
 ;--------------------------------------------
 RSEG ?SU?PUTC
 _putc:
         push ACC
         Push PSW
         mov a,r7
         CLR txd_pin                     ;Drop line for start bit
         MOV R0,#BITTIM          ;Wait full bit-time
         DJNZ R0,$                       ;For START bit
         MOV R1,#8                       ;Send 8 bits
 putc1:
         RRC A                           ;Move next bit into carry
         MOV txd_pin,C           ;Write next bit
         MOV R0,#BITTIM          ;Wait full bit-time
         DJNZ R0,$                       ;For DATA bit
         DJNZ R1,putc1           ;write 8 bits
         SETB txd_pin            ;Set line high
         RRC A                           ;Restore ACC contents
         MOV R0,#BITTIM          ;Wait full bit-time
         DJNZ R0,$                       ;For STOP bit
         POP PSW
         pop ACC
         RET

;--------------------------------------------
 ;To receive data Serially
 ;If you want to use this routine in your
 ;C program then define function prototype
 ; as:
 ;       unsigned char getc(void);
 ;
 ;       Usage:
 ;               data = getc();
 ;       Return value:
 ;               Returns data received
 ;
 ;
 ;If you are using it in assembly program
 ;       Usage:
 ;               lcall getc
 ;       Return:
 ;               data received is stored in R7
 ;--------------------------------------------

RSEG ?SU?GETC
 getc:
         Push ACC
         Push PSW
         JB rxd_pin,$            ;Wait for start bit
         MOV R0,#BITTIM/2        ;Wait 1/2 bit-time
         DJNZ R0,$                       ;To sample in middle
         JB rxd_pin,getc         ;Insure valid
         MOV R1,#8                       ;Read 8 bits
 getc1:
         MOV R0,#BITTIM          ;Wait full bit-time
         DJNZ R0,$                       ;For DATA bit
         MOV C,rxd_pin           ;Read bit
         RRC A                           ;Shift it into ACC
         DJNZ R1,getc1           ;read 8 bits
         mov r7,a
         POP PSW
         pop ACC
         RET                                     ;go home

#pragma ENDASM



void main(void)
{
while(1){
  putc('A');
  }

  //P0 = !P1;

}


above is the code which i have....
 
Last edited by a moderator:

Is your Code purely assenbly program or purely C program or C with inline assembly? It appears as assembly language file but you have added C code into it which is wrong.

_putc: and getc: are functions to send and receive data Serially. If you want to call those functions in asm code you have to use ACALL _putc and ACALL getc. You have inserted some putc() function call which doesn't have a function definition if it is a C program. Either write a C program or asm program or C with insline assembly and not asm file with inline C.

If you write function definitions of putc and getc then you dont need the asm code of _putc and getc.
 
Last edited:

Is your Code purelu assenbly program or purely C program or C with inline assembly? It appears as assembly language file but you have added C code into it which is wrong.

_putc: and getc: are functions to send and receive data Serially. If you want to call those functions in asm code you have to use ACALL _putc and ACALL getc. You have inserted some putc() function call which doesn't have a function definition if it is a C program. Either write a C program or asm program or C with insline assembly and not asm file with inline C.

If you write function definitions of putc and getc then you dont need the asm code of _putc and getc.
firstly thanks....
do you have code for the same in c??
i m confused how to convert _putc and getc into c..
please help me...
 


If GSM modem doesn't send any data to uC but only receives at commands from uC and rfid only sends data and doesn't receive data from uC then you can connect uC Rx to RFID and uC Tx to GSM modem. If GSM needs to send and receive data between uC then you need hardware uart for GSM and bit-banged uart for RFID. In bit-banged there will be no interrupt and baudrate will be slow. The link I provided there is also a project of bit-banged UART. Search for it.
 
Last edited:

If GSM modem doesn't send any data to uC but only receives at commands from uC and rfid only sends data and doesn't receive data from uC then you can connect uC Rx to RFID and uC Tx to GSM modem. If GSM needs to send and receive data between uC then you need hardware uart for GSM and bit -banged uart for RFID. In bit-banged there will be no interrupt and baudrate will be slow. The the link I provided there is also an project of bit-banged UART. Search for it.

sir,
yes i will definitely use bit banging for RF-ID because rf-id only will send data.
i searched for bit banging on the link u have given..they have used bit banging for I2C.i know nothing about I2C.
how can i use it for reading data from RF-ID?
because there is no ack signal for rf-id like I2C.
RF-ID will send 12 byte data.
 


First do the RFID part in your project. If the baudrate of the RFID matches with bitbanged spped and you get data successfully then only do the GSM part.

https://saeedsolutions.blogspot.in/2012/07/pic12f675-software-uart-bit-banging.html
https://saeedsolutions.blogspot.in/2012/10/pic16f84a-software-uart-bit-banging.html

The above codes are for PIC but as it is software UART the code can be used for any uC.

thank you sir...
i will do the rfid part first...i willl tell you results...
 

thank you sir...
i will do the rfid part first...i willl tell you results...

sir,
i have written following code for receving data from RF-ID..actually i dont have lcd on my development board.so i have used LED's..but its not working..
Code:
#include<reg51f.h>
#include<string.h>

#define Baudrate     2400
#define OneBitDelay  (1000000/Baudrate)
sbit  UART_RX=P2^0;
sbit  UART_TX=P2^1;

void __delay_us(unsigned int d)
{
   unsigned int i, limit;
   limit = d/15;

   for(i=0;i<limit;i++);
}

void init(void)
{
UART_RX = 1;  //set as i/p
UART_TX = 0;  //set as o/p
}

unsigned char receive(void)
{
unsigned char DataValue = 0,i;

	//wait for start bit
	while(UART_RX==1);

	__delay_us(OneBitDelay);
	__delay_us(OneBitDelay/2);   // Take sample value in the mid of bit duration

	for (  i = 0; i < 8; i++ )
	{
		if ( UART_RX == 1 )   //if received bit is high
		{
			DataValue += (1<<i);
		}

		__delay_us(OneBitDelay);
	}

	// Check for stop bit
	if ( UART_RX == 1 )       //Stop bit should be high
	{
		__delay_us(OneBitDelay/2);
		P1=0xff;	
            __delay_us(60000);
                P1=0x00;
		return DataValue;
	}
	else                      //some error occurred !
	{
		__delay_us(OneBitDelay/2);
		return 0x000;
	}
}


void rfid_data(void)
{
unsigned char d[12]=0,i;

for(i=0;i<12;i++)
{
d[i]=receive();

}

}


void main(void)
{
P1=0x00;  // for LED'S
init();
while(1)
{
rfid_data();
}
}

please suggest me changes as early as possible....thank you...
 

sir,
i have written following code for receving data from RF-ID..actually i dont have lcd on my development board.so i have used LED's..but its not working..
Code:
#include<reg51f.h>
#include<string.h>

#define Baudrate     2400
#define OneBitDelay  (1000000/Baudrate)
sbit  UART_RX=P2^0;
sbit  UART_TX=P2^1;

void __delay_us(unsigned int d)
{
   unsigned int i, limit;
   limit = d/15;

   for(i=0;i<limit;i++);
}

void init(void)
{
UART_RX = 1;  //set as i/p
UART_TX = 0;  //set as o/p
}

unsigned char receive(void)
{
unsigned char DataValue = 0,i;

	//wait for start bit
	while(UART_RX==1);

	__delay_us(OneBitDelay);
	__delay_us(OneBitDelay/2);   // Take sample value in the mid of bit duration

	for (  i = 0; i < 8; i++ )
	{
		if ( UART_RX == 1 )   //if received bit is high
		{
			DataValue += (1<<i);
		}

		__delay_us(OneBitDelay);
	}

	// Check for stop bit
	if ( UART_RX == 1 )       //Stop bit should be high
	{
		__delay_us(OneBitDelay/2);
		P1=0xff;	
            __delay_us(60000);
                P1=0x00;
		return DataValue;
	}
	else                      //some error occurred !
	{
		__delay_us(OneBitDelay/2);
		return 0x000;
	}
}


void rfid_data(void)
{
unsigned char d[12]=0,i;

for(i=0;i<12;i++)
{
d[i]=receive();

}

}


void main(void)
{
P1=0x00;  // for LED'S
init();
while(1)
{
rfid_data();
}
}

please suggest me changes as early as possible....thank you...

please reply me fast my firends......my waiting for your reply
 

you can aslo use any oyher pin for gsm modem to communicate ....u can recieve data and send by using 1/9600=104 microsecond of delay between each bit of rs232 frame......if u get any problem then plz ask here
 

you can aslo use any oyher pin for gsm modem to communicate ....u can recieve data and send by using 1/9600=104 microsecond of delay between each bit of rs232 frame......if u get any problem then plz ask here

but how to define function that will generate this much delay?
because its difficult to calculate delay provided by function in c...

- - - Updated - - -

but how to define function that will generate this much delay?
because its difficult to calculate delay provided by function in c...

the code i hv posted in post#12 is it right?
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top