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.

PIC UART not working in proteus .

Status
Not open for further replies.

azarutz

Member level 2
Joined
Mar 4, 2012
Messages
42
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
India
Activity points
1,579
hi i wrote program for pic uart in hitech-c and i am trying to simulate it in proteus and i need help .I used LCD to display data which i typed in virtual terminal is it works . what is virtual terminal in proteus . is it used to send and receive data from microcontroller .
Code:
#include<htc.h>
#include"lcd.h"
void pic_init();
void uart_init();
void transmit(char);
int data , rdata;
void interrupt ISR(void)
{
if(RCIF==1)
 { 
   if(OERR)
   {
    CREN=0;
    CREN=1;	
   }
  rdata=RCREG;   
 }
}
void main ()
{
 pic_init();
 uart_init();
 lcd_init(); 
 transmit('H');
 while(1)
 {
  printf("recived data=%c" ,rdata);  
 }
}
void pic_init()
{
 RC6=0;
 RC7=1;
 PORTD=0x00;
 PORTB=0xf8;
 GIE=1;
 PEIE=1;
 TXIE=1;
 RCIE=1; 
}
void uart_init()
{
 TX9=0;
 TXEN=1;
 SYNC=0;
 BRGH=1;
 SPEN=1;
 RX9=0;
 CREN=1;
 SPBRG = 129;
}
void transmit(char data)
{
 TXREG=data;
 while(!TRMT);
}
 

Could you post your proteus project files?
 

Hi , sorry for late reply . i attached my file .
 

Attachments

  • uart.rar
    14.3 KB · Views: 47


Code C - [expand]
1
2
3
4
5
void transmit(char data)
{
 TXREG=data;
 while(!TXIF);
}



Zip and post your MPLAB project files for quick solution.
 

Hi , thanks for reply here is my file
 

Attachments

  • uart.rar
    123.1 KB · Views: 39

Try these:

Code:
void pic_init()
{
 TRISC=0b10111111; 	// Was RC6=0; and RC7=1;
 TRISD=0x00;		// Was PORTD=0x00;
 TRISB=0xf8;		// Was PORTB=0xf8;
 
 GIE=1;
 PEIE=1;
 //TXIE=1;			// No need for this
 RCIE=1; 
}
void uart_init()
{
	
 SPEN=0;			// Missing: Disable UART to configure
 TX9=0;
 TXEN=1;
 SYNC=0;
 BRGH=1;
 
 RX9=0;
 CREN=1;
 SPBRG = 129;
 SPEN=1;			// Moved: Enable port once it's configured
}
 

For further clarification, the reason the transmit interrupt enable (TXIE=1) is not needed is that your interrupt service routine didn't do anything with it. This was the cause for the program to hang. When you sent the 'H', it triggered the transmit interrupt but you never handled it or cleared the flag so it got stuck in the service routine.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top