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.

The config bits settings for usart in pic18f4550 at baud rate 9600 using CCS

Status
Not open for further replies.

Chris zhi

Newbie level 5
Joined
Nov 7, 2008
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,374
I had problem using the usart feature of PIC18F4550.
I facing problem on sending data using TX pin of PIC18F4550.
I tried to send Eg: putc(0b10101010); to send 10101010 to other PIC.
It does not show anything.
the code for receiving is input = getch();
I using CCS software.
Thanks for your professional help.
 

Can you please post your code?
 

This is the code for transmitter side of PIC18F4550
#include "main.h"
#include "LCD.c"

void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab


// TODO: USER CODE!!
lcd_init();


while(true)
{


//Body
putc(0b10101010);
}
}
This is the main.h for PIC18F4550
#include <18F4550.h>
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOPBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL12 //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV4 //System Clock by 4
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES VREGEN //USB voltage regulator enabled
#FUSES ICPRT //ICPRT enabled

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)




This is the usart.h code for receiver side, I plan to use PIC16F877A
#ifndef _SERIAL_H_
#define _SERIAL_H_

#define BAUD 9600
#define FOSC 20000000L
#define NINE 0 /* Use 9bit communication? FALSE=8bit */

#define DIVIDER ((int)(FOSC/(16UL * BAUD) -1))
#define HIGH_SPEED 1

#if NINE == 1
#define NINE_BITS 0x40
#else
#define NINE_BITS 0
#endif

#if HIGH_SPEED == 1
#define SPEED 0x4
#else
#define SPEED 0
#endif

#if defined(_16F87) || defined(_16F88)
// #define RX_PIN TRISB2
// #define TX_PIN TRISB5
//#else
#define RX_PIN TRISC7
#define TX_PIN TRISC6
#endif

/* Serial initialization */
#define init_comms()\
RX_PIN = 1; \
TX_PIN = 1; \
SPBRG = DIVIDER; \
RCSTA = (NINE_BITS|0x90); \
TXSTA = (SPEED|NINE_BITS|0x20)

void putch(unsigned char);
unsigned char getch(void);
unsigned char getche(void);

#endif

Receiver code
#include <htc.h>
#include <stdio.h> //for sprintf
#include "lcd.h" // to call function
#include "usart.h"
#include "delay.h"

__CONFIG(0x3f72);

void main (void)
{
while(1)
{
unsigned char input;
input = getch();
PORTB = input;
}
}

**It does work as what I expect. Please advice.Thanks.
 

Hi,

Don't try with both circuits simultaneously;

First take the transmitter only; with an uart emulator (like uart-tool in pickit2 or in micro-c or hyperterminal ) check is it transmit correct data ?.
Then check receiver same way for correct receive of data.

Then you can connect both,

Hope this helps you.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top