NIALA
Junior Member level 1
- Joined
- Jun 9, 2010
- Messages
- 19
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 1,283
- Location
- Minneapolis
- Activity points
- 1,408
Hi , seeking a little help
My goal : establish serial communication between an hyper terminal and a PIC16F877A using a C code.
Tools : MPLAB X IDE V1.80 and the c compiler is XC8 Compiler.
I define a init file InitUART() to initialise the register
An infinite loop where I received and transmit a character through registers when they are full.
I wasnt able to establish communication so far and open for some suggestions.
thanks!!!
My goal : establish serial communication between an hyper terminal and a PIC16F877A using a C code.
Tools : MPLAB X IDE V1.80 and the c compiler is XC8 Compiler.
I define a init file InitUART() to initialise the register
An infinite loop where I received and transmit a character through registers when they are full.
I wasnt able to establish communication so far and open for some suggestions.
thanks!!!
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 #include <xc.h> #include <stdio.h> #include <stdlib.h> #include <usart.h> #pragma config "FOSC=XT" #pragma config "WDTE=OFF" #pragma config "BOREN=OFF" #pragma config "LVP=OFF" #pragma config "DEBUG=OFF" #ifndef _XTAL_FREQ #define _XTAL_FREQ 4000000 #endif #define BAUDRATE 9600 void InitUART (void); /* * */ int main(int argc, char** argv) { unsigned char ReceiveChar; // InitUART(); // while(1) { if(RCIF==1) { ReceiveChar=RCREG; if(TXIF==1) { TXREG=ReceiveChar+0x01; } } } return (EXIT_SUCCESS); } void InitUART (void) { SPBRG = ((_XTAL_FREQ/16)/BAUDRATE) -1; BRGH = 1; //Baud Rate Generator High Speed 1 SYNC = 0; //Asynchronous mode 0 SPEN = 1; //Serial Port Enable Bit 1 CREN = 1; //Continuous Receive Enable Bit Enable continuous receive 1 SREN = 0; //dont care in asynchronous mode TXIE = 1; //USART Transmit Interrupt Enable Bit , disable the USART transmit interrupt RCIE = 1; //USART Receive Interrupt Enable Bit , Enable the USART receive interrupt TX9 = 0; // 9bit transmit enable bit 0 select 8bit tran RX9 = 0; // 9bit receive enable bit 0 select 8bit recep TXEN = 0; // Transmit Enable Bit Transmit disabled 0 TXEN = 1; // Transmit Enable Bit Transmit enable 1 TRISCbits.TRISC6 = 0; // This sets pin RC6 to output (USART asynchronous transmit or synchronous clock) TRISCbits.TRISC7 = 1; // This sets pin RC7 to input (USART asynchronous receive or synchronous data) GIE = 1 ;//Global Interrupt Enable Bit: 1 Enables all unmasked interrupts PEIE = 1 ;//Peripheral Interrupt Enable Bit : 1 Enables all unmasked peripherals interrupts }
Last edited by a moderator: