Djsarkar
Member level 3
Hi
I have PIC18F45K80. I am using MPLABX 5.40 and XC8 2.30. I want to send data from PIC to my laptop
Here is my program
when I run code I am getting garbage value on hyper terminal.
Hyper terminal settings
baud rate 9600
Data bit 8
parity none
stop bit 1
In schematic, connections between the PIC and the MAX232 swapped.
but expert suggested following connection
The PIC TX should connect to T1IN (pin 11)
and PIC RX should connect to R1OUT (pin 12)
so I have developed my own circuit
Red 5V
Black gnd
gray gnd
Blue Input from RC7
Yellow output from maxrs232N
When I see data with developed circuit I don't get any value on hyper terminal
Any help would be appreciated
I have PIC18F45K80. I am using MPLABX 5.40 and XC8 2.30. I want to send data from PIC to my laptop
Here is my program
C:
#define _XTAL_FREQ 8000000
#include <xc.h>
// PIC18F45K80 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1L
#pragma config RETEN = OFF // VREG Sleep Enable bit (Ultra low-power regulator is Disabled (Controlled by REGSLP bit))
#pragma config INTOSCSEL = HIGH // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep)
#pragma config SOSCSEL = HIGH // SOSC Power Selection and mode Configuration bits (High Power SOSC circuit selected)
#pragma config XINST = OFF // Extended Instruction Set (Enabled)
// CONFIG1H
#pragma config FOSC = INTIO2 // Oscillator (Internal RC oscillator)
#pragma config PLLCFG = OFF // PLL x4 Enable bit (Disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor (Disabled)
#pragma config IESO = OFF // Internal External Oscillator Switch Over Mode (Disabled)
// CONFIG2L
#pragma config PWRTEN = OFF // Power Up Timer (Disabled)
#pragma config BOREN = SBORDIS // Brown Out Detect (Enabled in hardware, SBOREN disabled)
#pragma config BORV = 3 // Brown-out Reset Voltage bits (1.8V)
#pragma config BORPWR = ZPBORMV // BORMV Power level (ZPBORMV instead of BORMV is selected)
// CONFIG2H
#pragma config WDTEN = OFF // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WDTPS = 1048576 // Watchdog Postscaler (1:1048576)
// CONFIG3H
#pragma config CANMX = PORTB // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively)
#pragma config MSSPMSK = MSK7 // MSSP address masking (7 Bit address masking mode)
#pragma config MCLRE = ON // Master Clear Enable (MCLR Enabled, RE3 Disabled)
// CONFIG4L
#pragma config STVREN = ON // Stack Overflow Reset (Enabled)
#pragma config BBSIZ = BB2K // Boot Block Size (2K word Boot Block size)
// CONFIG5L
#pragma config CP0 = OFF // Code Protect 00800-01FFF (Disabled)
#pragma config CP1 = OFF // Code Protect 02000-03FFF (Disabled)
#pragma config CP2 = OFF // Code Protect 04000-05FFF (Disabled)
#pragma config CP3 = OFF // Code Protect 06000-07FFF (Disabled)
// CONFIG5H
#pragma config CPB = OFF // Code Protect Boot (Disabled)
#pragma config CPD = OFF // Data EE Read Protect (Disabled)
// CONFIG6L
#pragma config WRT0 = OFF // Table Write Protect 00800-01FFF (Disabled)
#pragma config WRT1 = OFF // Table Write Protect 02000-03FFF (Disabled)
#pragma config WRT2 = OFF // Table Write Protect 04000-05FFF (Disabled)
#pragma config WRT3 = OFF // Table Write Protect 06000-07FFF (Disabled)
// CONFIG6H
#pragma config WRTC = OFF // Config. Write Protect (Disabled)
#pragma config WRTB = OFF // Table Write Protect Boot (Disabled)
#pragma config WRTD = OFF // Data EE Write Protect (Disabled)
// CONFIG7L
#pragma config EBTR0 = OFF // Table Read Protect 00800-01FFF (Disabled)
#pragma config EBTR1 = OFF // Table Read Protect 02000-03FFF (Disabled)
#pragma config EBTR2 = OFF // Table Read Protect 04000-05FFF (Disabled)
#pragma config EBTR3 = OFF // Table Read Protect 06000-07FFF (Disabled)
// CONFIG7H
#pragma config EBTRB = OFF // Table Read Protect Boot (Disabled)
void Port_Initialized (void)
{
LATA = LATB = LATC = LATD = LATE = 0;
TRISA = 0b0000000;// all are output, Unused
TRISB = 0b0000000;// all are output, Unused
TRISC = 0b1000000; // TX Pin set as output, RX Pin set as input
TRISD = 0b0000000;//all are output, Unused
TRISE = 0b0000000;// All are output, Unused
ANCON0 = 0; // digital port
ANCON1 = 0; // digital port
CM1CON = 0; // Comparator off
CM2CON = 0; // Comparator off
ADCON0 = 0; // A/D conversion Disabled
}
void send(char message)
{
while(TXIF==0); // Wait till the transmitter register becomes empty
TXREG = message;
}
void string(char *p)
{
while(*p != '\0') {
send(*p);
__delay_ms(1);
p++;
}
}
void Uart_Initialized(void)
{
//TXSTAx TRANSMIT STATUS AND CONTROL REGISTER
TXSTAbits.CSRC = 0; //: Don?t care.
TXSTAbits.TX9 = 0; //Selects 8-bit transmissionbit
TXSTAbits.TXEN = 1; // Transmit Enable
TXSTAbits.SYNC = 0; // Asynchronous mode
TXSTAbits.SENDB = 0;
TXSTAbits.BRGH = 1; // High speed mode
TXSTAbits.TX9D = 0;
//RCSTAx: RECEIVE STATUS AND CONTROL REGISTER
RCSTAbits.SPEN = 1 ; //Serial port enabled
RCSTAbits.RX9 = 0; //Selects 8-bit reception
RCSTAbits.SREN = 1 ;//Don?t care.
RCSTAbits.CREN = 1 ;// Enables receiver
RCSTAbits.ADDEN = 0; //
RCSTAbits.FERR = 0 ;// No framing error
RCSTAbits.OERR = 1 ; // Overrun error
RCSTAbits.RX9D = 0 ; //Selects 8-bit reception
SPBRG = 51;
}
void main(void)
{
char message[]= {"Hello world"};
Port_Initialized ();
Uart_Initialized ();
string(message);
while (1)
{
}
}
when I run code I am getting garbage value on hyper terminal.
Hyper terminal settings
baud rate 9600
Data bit 8
parity none
stop bit 1
In schematic, connections between the PIC and the MAX232 swapped.
but expert suggested following connection
The PIC TX should connect to T1IN (pin 11)
and PIC RX should connect to R1OUT (pin 12)
so I have developed my own circuit
Red 5V
Black gnd
gray gnd
Blue Input from RC7
Yellow output from maxrs232N
When I see data with developed circuit I don't get any value on hyper terminal
Any help would be appreciated
Attachments
Last edited: