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
Post the code here.
#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;
}
firstly thanks....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.
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.
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...
#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();
}
}
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...
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...
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?