Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC18f4520 circuit problem??

Status
Not open for further replies.

haowhaow

New Member
hi, im newbie in programming.....

im using MPlab to simulate my project.....
im using Hi tech compiler....when i start simulation....
i get an error of " [pic18] illegal FOSC bits (0b1010) in CONFIG1H "...
may i know what is the problem??

here is my coding ....

#include <htc.h>
#include <math.h>

#include "lcd.h"


//Chip Settings
__CONFIG(1,0x0200);
__CONFIG(2,0X1E1F);
__CONFIG(3,0X8100);
__CONFIG(4,0X00C1);
__CONFIG(5,0XC00F);

//Simple Delay Routine
void Wait(unsigned int delay)
{
for(;delay;delay--)
__delay_us(100);
}


//Function to Initialise the ADC Module
void ADCInit()
{
//We use default value for +/- Vref
//VCFG0=0,VCFG1=0
//That means +Vref = Vdd (5v) and -Vref=GEN

//Port Configuration
//We also use default value here too
//All ANx channels are Analog

/*
ADCON2

*ADC Result Right Justified.
*Acquisition Time = 2TAD
*Conversion Clock = 32 Tosc
*/

ADCON2=0b10001010;
}

//Function to Read given ADC channel (0-13)
unsigned int ADCRead(unsigned char ch)
{

if(ch>13) return 0; //Invalid Channel

ADCON0=0x00;

ADCON0=(ch<<2); //Select ADC Channel

ADON=1; //switch on the adc module

GODONE=1;//Start conversion

while(GODONE); //wait for the conversion to finish

ADON=0; //switch off adc

return ADRES;

}
void main()
{
//Let the LCD Module start up
Wait(100);

//Initialize the LCD Module
LCDInit(LS_BLINK);

//Initialize the ADC Module
ADCInit();

//Clear the Module
LCDClear();

//Write a string at current cursor pos
LCDWriteString("Temperature:");
LCDWriteStringXY(4,1,"Degree C");

/* while(1)
{
unsigned int val; //ADC Value
unsigned int t; //Temperature


val=ADCRead(0); //Read Channel 0

//t=round(val*0.48876);//Convert to Degree Celcius
t=round(val*100);

LCDWriteIntXY(0,1,t,3);//Prit IT!


Wait(1000);
}
*/

while(1)
{
unsigned int val;
unsigned int t; //Temperature

val=ADCRead(0); //Read Channel 0
//voltage= ((val)/1100)*5;
//The above formula give voltage in Volts, to get Voltage in mili Volts (mV) we must multiply it with 1000, so

//voltage=((val)/1100)*5*1000); //Voltage is in mV
//since (1/220)mV = 1 degree, to get temperature we must divide it by 1/220, so

//t=((val)/1100)*5*1000*220); //t is in degree centigrade
//simplifying further we get

//t=((val/1100)*1100000);
//t=(val*1000);
//we round off this value, so

t=round(val*1000);

LCDWriteIntXY(0,1,t,3);//Prit IT!


Wait(1000);

}
}




below i have attach my problem ....hope that anyone here can help me solve it~appreciated it much!!
 

Attachments

  • untitled.JPG
    untitled.JPG
    197.5 KB · Views: 530
Your config settings are invalid. See attached for valid config settings and then enter them in the form,
Code:
#pragma config WDT = OFF, LVP = OFF, OSC = INTIO67
NEVER use stupid hex values in config settings and then expect anyone to help debug.

Edit, looking at the pdf, the above will probably be what you need. Just copy and past it instead of all the config lines.

Mike.
 

Attachments

  • C18_Config_Settings_51537e.pdf
    2.9 MB · Views: 654
Last edited:
oh....i get what u mean d....hehe...anyway thankz
but now my lcd display can't display any value(js show "0)." ) ....what problem again??
 
Your config settings are invalid. See attached for valid config settings and then enter them in the form,
Code:
#pragma config WDT = OFF, LVP = OFF, OSC = INTIO67
NEVER use stupid hex values in config settings and then expect anyone to help debug.

Edit, looking at the pdf, the above will probably be what you need. Just copy and past it instead of all the config lines.

Mike.

im using HI tech compiler...can i still set the code as what u had teach me???
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top