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.

[SOLVED] PC -> Pic16f877a serial data transmission RS232

Status
Not open for further replies.

mturna

Junior Member level 2
Joined
Apr 3, 2011
Messages
20
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,283
Activity points
1,418
Hi guys,
My problem is about 16f877a. I am sending data from computer to the pic via RS232. I checked RS232 output max232 output and the data enter RC7 (receiver pin) they are all correct. But the pic can't receive data correctly.
I am using
data=getc();
function to get a byte data but how much should I wait after this (optimum value) or should I?.
And how can use the interrupt I? Because I used some but they didn't worked. For example:
#int_RDA
void RDA_isr(void)
{ disable_interrupts(int_rda)
c = getc(); // Get character from PC
output_high(red);
delay_ms(3000);
output_low(red);
}
the led hasn't turn on ever. How can I solve this?
Thank you.
 

This example demonstrates simple data exchange via software UART. If MCU is connected to the PC, you can test the example from the mikroC PRO for PIC USART Terminal Tool.




char i, error, byte_read; // Auxiliary variables

void main(){

ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;

TRISB = 0x00; // Set PORTB as output (error signalization)
PORTB = 0; // No error

error = Soft_UART_Init(&PORTC, 7, 6, 14400, 0); // Initialize Soft UART at 14400 bps
if (error > 0) {
PORTB = error; // Signalize Init error
while(1) ; // Stop program
}
Delay_ms(100);

for (i = 'z'; i >= 'A'; i--) { // Send bytes from 'z' downto 'A'
Soft_UART_Write(i);
Delay_ms(100);
}

while(1) { // Endless loop
byte_read = Soft_UART_Read(&error); // Read byte, then test error flag
if (error) // If error was detected
PORTB = error; // signal it on PORTB
else
Soft_UART_Write(byte_read); // If error was not detected, return byte read
}
}
 

Assuming you are using CCS compiler (PIC C Compiler)
this is my own working code of some project..

// ************ Serial Data Receive ************ //
#int_rda
void Serial_Receive(void)
{
ch = getch();
if(ch == '#')
{
Serial.IsReceiving = 1;
}
else if(ch == '*' && Serial.IsReceiving == 1)
{
Serial.DataReceived[Serial.Count] = ch;
//printf("%c",Serial.DataReceived[Serial.Count]);
Serial.IsReceived = 1;
Serial.Count = 0;
Serial.IsReceiving = 0;
}
else if(Serial.IsReceiving == 1)
{
Serial.DataReceived[Serial.Count] = ch;
//printf("%c",Serial.DataReceived[Serial.Count]);
Serial.Count++;
}


}

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

also if you are using serial interrupt then you should enable it in the main program like that

//****************** ENABLING INTERRUPTS *********************//

enable_interrupts (INT_RDA) ; // Setup serial interrupt
enable_interrupts(GLOBAL);

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

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top