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.

trouble with PIC18F458

Status
Not open for further replies.

majestrix

New Member
hi, i recently bought a PIC18F458 development board (https://www.futurlec.com/PIC18F458_Development_Board.shtml). when the MC came the code examples were all in basic, but i'm not very good at it... but i have seen some PIC18f452 with C++ codes that one of my friends has written, and i tried to compile one of his 452 programs (that blinks an LED at RB0) with 458 header file. i used MPLAB and the c18 compiler.. and used the uploader program that came with my board (CP458V3.exe) to upload the program to my PIC.. but nothing happens, when i run it. but i have tried uploading a hex file that came with my board and it works, so i know my board works and the uploader as well works...
here follows the source code that i'm using.

/*
* This program blinks an LED at PORTB RB0.
*/

#include <p18f458.h> /* for TRISB and PORTB declarations */
#include <delays.h>

/*
* - set HS oscillator
* - disable watchdog timer
* - disable low voltage programming
*/

#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF

int on;
int off;

void main (void)
{
on = 0x01;
off = 0x00;
PORTA = 0; /*clear PORTB */
TRISA = 0; /* configure PORTB for output */

while (1)
{
PORTA = on;
Delay10KTCYx (255);

PORTA = off;
Delay10KTCYx (255);
}
}


so i would be very glad if any one could tell me what i'm doing wrong and how to correct it, or give me a C++ code example for PIC18F458. please help me... and i as well wanna to know if there is a difference between "hex files" and "intel hex files"...
i could be reached via email at majestricx@hotmail.com, if needed...
thanks a lot

-Hasan
 
That's C, not C++, by the way. C++ is not used for microcontrollers and it is likely it never will.

Check your #pragma list to see if you have everything appropriate to the 458.

I haven't compiled with MCC18 in a long time so I'm not sure, but don't you have to set which part you have in the compiler options? I don't think #include <pic18f458.h> does it.
 
thanks for the correction, Oznog..
yeah, i do have to set the part number in one of the compiler options in MPLAB to PIC18F458, before i complie it... and i did as well checked the #pragma configurations and i didnt seem to find anything wrong in my code.. well, still nothing happens... :cry:
Oznog, may i know which compliler or which language u are using to program the PIC..???
thanks a lot
 
majestrix said:
* This program blinks an LED at PORTB RB0.
*/

Oh man, you said LED at port B, but you(or your friend) coded the routine on port A.


Code:
PORTA = 0; /*clear PORTB */ 
TRISA = 0; /* configure PORTB for output */ 

while (1) 
{ 
PORTA = on; 
Delay10KTCYx (255); 

PORTA = off; 
Delay10KTCYx (255);
 
oh, i'm so sorry for that.. i actaully meant to say RA0.. guys, so sorry for the typo error.. that arose coz we were just playing around with the program to see if portA works when portB didnt work.. thats y its as port B in comments too.. so sorry abut that...
 
hi again... i managed to download a HiTech PICC-18 compiler a demo version... i guess its close to what Oznog is using.. right? so Oznog or anyone else, if you have any simlpe PIC18F458 C programs, could you please let me have a look at it.. i just need to get started on it... as soon as that program works, i guess i could build from there... i just dont wanna go to assembly, unless i have no other choice.. coz i used to write assembly programs for lab practicals for infenion's C167 MC, and it was a pretty big mess even to do something simple, mostly troublesome to debug..
so if anyone has a simple program can u pls let me see it..
thanks a lot.
majestricx@hotmail.com
 
that program your friend gave you is a valid program, it's just not complete.

visit Microchip and download the datasheet for your PIC

make sure every config option register set (there are lots of them for the 18F), don't just assume the defaults are what you need

but my bet is all you need to add is ADCON1 = 7;
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top