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.

RF transmitter problem

Status
Not open for further replies.

areeckal

Member level 2
Joined
Jan 22, 2011
Messages
42
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,567
I did some code in mplab using hitech compiler for RF transmission.
When i am simulating in mplab i am getting correct output in uart I/O tab. But iam not obtaining any value in the portC ie, TX pin. I tried simulating in proteus by connecting an led to the RC. But nothing is coming. Is there any problem with my code? How to simulate it correctly?
Tx.c
Code:
#include <htc.h>
#include "usart.h"

//Chip Settings
__CONFIG(1,0x0200);
__CONFIG(2,0X1E1F);
__CONFIG(3,0X8100);
__CONFIG(4,0X00C1);
__CONFIG(5,0XC00F);

void main()
{
	int addr=0, data=1,checksum;
	//Initialize the USART
	USARTInit();
	char sendData[5];
    sendData[0]='J';
    sendData[1]='S';
	sendData[2]='0';
	sendData[3]='1';
	sendData[4]=sendData[2]+sendData[3];
	//Transmit Data
	while(1)
	{
		USARTWriteByte(sendData[0]);
		//_delay(100);
		//Send synchronization Byte	
		USARTWriteByte(sendData[1]);
		//_delay(100);
		//AddressByte
		USARTWriteByte(sendData[2]);
		//_delay(100);
		//Data byte for start time
		USARTWriteByte(sendData[3]);
		//_delay(100);
		//Checksum
		//checksum=addr+data;		
		USARTWriteByte(sendData[4]);
	//	TXEN=0;
		//_delay(100);
	}
}
usart.c
Code:
/*****************************************************************

BAUD RATE:57600 Bits per Second
CRYSTAL Frequency: 20MHz

Target Chip: PIC18F4520
Target Compiler: HI-TECH C For PIC18 (http://www.htsoft.com/)
Project: MPLAP Project File

*****************************************************************/

#include <htc.h>
#include<stdio.h>

#include "usart.h"

void USARTInit()
{
	//Baud Rate = 57600 Bits per Second
	//*** Note: Valid On 20MHz Crystal ONLY ***
	//For other crystal freq calculate new values for SPBRG
	SPBRG=86;

	//TXSTA REG
	TXEN=1;
	BRGH=0;
	SYNC=0;
	//RCSTA
	SPEN=1;
	CREN=1;	//Enable Receiver (RX)
	
	//BAUDCON
	BRG16=1;
	//TRISC
	TRISC=0x00;

}

void USARTWriteByte(char ch)
{
	//Wait for TXREG Buffer to become available
	while(!TXIF);

	//Write data
	TXREG=ch;
}

void USARTWriteString(const char *str)
{
	while((*str)!='\0')
	{
		//Wait for TXREG Buffer to become available
		while(!TXIF);

		//Write data
		TXREG=(*str);

		//Next goto char
		str++;
	}
}

/*

Writes a line of text to USART and goes to new line
The new line is Windows style CR/LF pair.

This will work on Hyper Terminal Only NOT on Linux

*/

void USARTWriteLine(const char *ln)
{
	USARTWriteString(ln);
	USARTWriteString("\r\n");
}

void USARTWriteInt(int val,unsigned char field_length)
{
	if(val<0) 
	{
		USARTWriteByte('-');	//Write '-' sign for negative numbers.
		val=(val*(-1));				//Make it positive.
	}

	//Convert Number To String and pump over Tx Channel.
	char str[5]={0,0,0,0,0};
	int i=4,j=0;
	while(val)
	{
		str[i]=val%10;
		val=val/10;
		i--;
	}
	if(field_length>5)
		while(str[j]==0) j++;
	else
		j=5-field_length;
	
	for(i=j;i<5;i++)
	{
		USARTWriteByte(str[i]);
	}
}


unsigned char USARTReadByte()
{
	while(!RCIF);	//Wait for a byte
	
	return RCREG;
}
Help pls
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top