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.

Why is this code not working?

Status
Not open for further replies.

Neyolight

Full Member level 5
Joined
Aug 29, 2011
Messages
306
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
World
Activity points
3,624
Im using PIC18f4620 on Picdem2 borad , Serial to USB adapter and hyperterminal on windows 7.

A simple "hello world" USART code. It doesnt work, doesnt even lite the 4 port B LEDs :roll:

Code:
#include <p18f4620.h>
#include <stdio.h>
#include <delays.h>
#include <usart.h>
 


#pragma config OSC = HS, LVP=OFF ,MCLRE =ON 
 
void setup(void)
{
	/* Port Set Up*/
	ADCON1 = 0b00001111; //set all pins to digital mode
	TRISD = 0;
	TRISA = 0;
	TRISB = 0b00000000; 
	TRISC = 0b10000000; // RX is an input, TX is output
 	PORTBbits.RB0=1; // turn on the 4 LEDS
 	PORTBbits.RB1=1;
 	PORTBbits.RB2=1;
 	PORTBbits.RB3=1;
 	
	/* Interrupt Setup */
	INTCON = 0x00; /* Clear Registers */
	PIR1 = 0x00;
	PIE1 = 0x00;
	TMR1L = 0x00;
	TMR1H = 0x00;
	T1CON = 0x00;
	RCON = 0x00; 
 
             /* RS232 Enable */
	RCSTA = 0b10000000;
	TXSTA = 0b00100000;
	BAUDCON = 0b00000000;		
	//SPBRG = 51; //FOSC = 8.000 MHz,SYNC = 0, BRGH = 0, BRG16 = 0
	OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 51);
 
 
 
	/* Clock Setup*/ 
	OSCCON = 0b01110110; //select 8 MHz clock
}	
 

#pragma code
void main(void)
{
	setup();
		
	while (1)
	{
		putrsUSART("Hello");
	//	while(BusyUSART());
		Delay1KTCYx(1000);
		
	}
}

Thanks :smile:
 

in my view you should check the your configuration for PIC18F configuration is different-

I had made configuration like

// Configurations
__code char __at __CONFIG1L conf1 = 0X04; // Select HS PLL OSC
__code char __at __CONFIG1H conf2 = 0xCF;
__code char __at __CONFIG2L conf3 = 0x00;
__code char __at __CONFIG2H conf4 = 0x00;
__code char __at __CONFIG3H conf5 = 0x80;
__code char __at __CONFIG4L conf6 = 0x81;

It is slightly different than PIC16F configuation ....

refer the code on link -

Microchip PIC micros and C - source and sample code

Good Luck
 
Hey thanks but im not coding in HI-Tech C. Im usign C18 complier:roll:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top