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.

Serial communication help!!

Status
Not open for further replies.

piscaroy

Junior Member level 3
Joined
Aug 12, 2004
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
531
hi,
i encountered a problem with my serial communication when doing some sending and recieving of datas...when i use the serial com tool(Advanced Serial Port Monitor--ASPM) to send data to my PIC18f452, it is working fine(which means it can receive and display on LCD)but when i change to another part of my project, which is to use Visual Basic(mscom coding) program to send Data to my PIC, this time the PIC only able to detect data at serial com port,but unable to display the Data on the LCD...i have tested the sending of the VB codes..i used the VB to send data thru com port1 and use the ASPM to spy on the port..and is able to capture the data and display in the window...i oso tried changing the baud rate but it still doesnt work..how come will like dat?? pls help...thanks alot

my codes...

Code:
#include <p18f452.h>
#include <usart.h>
#include <stdlib.h>
#include <delays.h>
#include <xlcd.h>
#include <string.h>

#define BUFF_SIZE 	20
#define SIZE1 		15   
#define MAX_CHAR	15

//helper functions
void readFrmEEPROM(int address, int bytes, char *tempStr);
void writeStr2EEPROM(int address, char *str);


/************************************************************************/
/*******************          SUBROUTINES         ***********************/
/************************************************************************/

/********************************************/
/**********   LCD Subroutines ***************/
/********************************************/

//	I/O Configuration
void InitializePORTS(void)
{
	TRISC= 0xE0;
}

// LCD initialisation
void DelayPORXLCD(  )
	{
	Delay1KTCYx(15); 			//Delay of 15ms
	
	}
void	DelayXLCD(void)
	{
		Delay1KTCYx(5);
	}
void	DelayFor18TCY(void)
	{
		Nop();
		Nop();
		Nop();
		Nop();
		Nop();
		Nop();
		Nop();
		Nop();
		Nop();
		Nop();    
		Nop();
		Nop();
		Nop();
		Nop();
		Nop();
		Nop();
		return;
			
	}
void LCDinit(void){

		PORTA=0x00;

		ADCON1 = 0x0E;

		OpenXLCD(0x28);	//Init LCD 4-bit interface lower nibble, 
						//multiple line

		DelayXLCD();
		
			

}
void LCDclr(void){
WriteCmdXLCD(0x01);
DelayXLCD();
}
/********************end of LCD rountine***************************/

void Delay5s(void){
Delay10KTCYx(250);
Delay10KTCYx(250);
}

/****************************************************/
/**********      EEPROM Subroutine    ***************/
/****************************************************/
//EEprom Initialisation
void EEpromInit(void){
   EECON1 = 0x00; 					

   EECON1bits.WREN = 1; 			//set EECON reg to allow write cycles

}		

unsigned char ReadEEPROM(unsigned char Adresse) 
{ 
	
      EEADR = Adresse; 

      EECON1bits.EEPGD = 0;		//access DATA EEPROM 
      EECON1bits.CFGS = 0; 		//access Flash program/Data EEprom memory 

      EECON1bits.RD = 1; 		//enable Read
      return EEDATA; 			//data is stored here
} 



void WriteEEPROM(unsigned char Adresse, char Data) 
{ 

   EEADR = Adresse; 			//
   EEDATA = Data; 				//
   EECON1bits.EEPGD = 0; 		
   EECON1bits.CFGS = 0; 
   EECON1bits.WREN = 1; 

   INTCONbits.GIEH = 0; 			//disable interrupts
   INTCONbits.GIEL = 0; 

   EECON2 = 0x55; 
   EECON2 = 0xAA; 

   EECON1bits.WR = 1; 
while(EECON1bits.WR);			//Waiting for WR to be clear
   EECON1bits.WREN = 0; 			//disable writes on write complete


}
/*******************************************************/
/*Function to write a string to EEprom given an address*/
/*******************************************************/

void writeStr2EEPROM(int address, char *str) {
int len;
int i=0;

len = strlen(str);

	//loop to write each character to EEPROM
  for(i=0; i<MAX_CHAR ; i++) {
	WriteEEPROM(address+i , str[i]);
	//test = readEERPOM(EEADR+i);
	}
}


/*******************************************************/
/*Function to read x bytes from eeprom given an address*/
/*x bytes must be at most 15 characters                */
/*******************************************************/
void readFrmEEPROM(int address, int bytes, char *tempStr){
int i=0;

if (bytes <= MAX_CHAR){
	for(i=0;i<bytes;i++) {
	tempStr[i] = ReadEEPROM(address+i);
}
}
tempStr[bytes] = '\0';
}
/***********************END of EEPROM routine******************/



/**************************************************************/
/*                         MAIN PROGRAM                       */
/**************************************************************/


//main programm
void main(){
	int writeAdd,readAdd;
	char recData[15];
	char tempRead[15];
	char counter;
	char counter1;
	
	InitializePORTS();
	EEpromInit();
	LCDinit();

	
	
	//configure USART
	OpenUSART(USART_TX_INT_OFF &
			USART_RX_INT_OFF &
			USART_ASYNCH_MODE &
			USART_EIGHT_BIT &
			USART_CONT_RX &
			USART_BRGH_HIGH, 
			25);

		Delay10KTCYx(50);   // delay 0.5 sec
			
while(1){	
			
		while(!DataRdyUSART());   //check whether data is received and available
			
			getsUSART(recData,17); //get 17 characters from serial com port
			counter=0;
		
		do{
			WriteEEPROM(counter,recData[counter]);
			counter++;
	
		}while(counter<16);

	
	putrsXLCD("waiting...");

	Delay10KTCYx(100);       //delay 1 sec

	WriteCmdXLCD(0x01);		//clr LCD 

		
		counter=0;
			
			
		do {
			tempRead[counter]=ReadEEPROM(counter);
			counter++;
		}while(counter<16);
			
	putsXLCD(tempRead);
		
	Delay10KTCYx(200);			//delay 2 secs
		
	WriteCmdXLCD(0x01);		// clr display
		
}

}


best regards
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top