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.

PIC18F242 program for PIC18F2420, does it Work?

Status
Not open for further replies.

ktkoota

New Member
hi,
I am working on a Senior Graduation project, and I'm given this task:
connect 4 switches to control 4 leds on "EasyPic5", in which PIC18F2420 is embded.
I solved this Task by MPLAB7 and Simulate it using PROTEUS 6. in MPLAB I created a project and by mistake i choosed PIC18F242
the code run succefuly and the Simulation also.. now I want to apply it to Easypic5 by loading the hex file through picflash programmer and it didn't work because the pic should be PIC18F2420 not 242. I created another project with pic182420 and the code run, but the simulation didn't work!!
so please if you can help the submition is by Tues. , please don't suggest to change the pic or change the software coz those are the available one.

code on pic18f242:

#include "pic18.h"
#include "config.h"
#include "delay.h"

main(void){

TRISB = 0x0F; //RB4,RB5,RB6 and RB7 are outputs, others inputs

RB4 = 0; // turn LED off
RB5 = 0; // turn LED off
RB6 = 0; // turn LED off
RB7 = 0; // turn LED off

while(1)
{
if(RB3 && RB2 && RB1 && RB0); //if all switches are not prssed(1111)
{
PORTB=PORTB & 0x0F; //LEds = 0000 ,, switches= 1111
while(RB3 &&RB2 && RB1 && RB0);
//DelayMs(30);
}
//---------------------------------------------------------------------

if(RB3 && RB2 && RB1 && !RB0) //if RB0 switche is prseed(1110)
{
PORTB=PORTB & 0x0F; //clear external values in portB
PORTB=PORTB | 0x10; //set values in portB=00010000
while(RB3 &&RB2 && RB1 && !RB0); // which is LED output RB4=1 ON
//DelayMs(30);
}
//---------------------------------------------------------------------
if(RB3 &&RB2 && !RB1 && RB0)
{
PORTB=PORTB & 0x0F; //Clear portB
PORTB=PORTB | 0x20; //Set RB5=1 LED ON
while(RB3 &&RB2 && !RB1 && RB0);
//DelayMs(30);
}
//---------------------------------------------------------------------
if(RB3 &&RB2 && !RB1 && !RB0) //12
{
PORTB=PORTB & 0x0F;
PORTB=PORTB | 0x30;
while(RB3 &&RB2 && !RB1 && !RB0);
//DelayMs(30);
}
//---------------------------------------------------------------------
if(RB3 && !RB2 && RB1 && RB0)
{
PORTB=PORTB & 0x0F;
PORTB=PORTB | 0x40;
while(RB3 &&!RB2 && RB1 && RB0);
//DelayMs(30);
}
//-------------------------------------------------------------------------

if(RB3 &&!RB2 && RB1 && !RB0)
{
PORTB=PORTB & 0x0F;
PORTB=PORTB | 0x50;
while(RB3 &&!RB2 && RB1 && !RB0);
//DelayMs(30);
}
//-------------------------------------------------------------------------
if(RB3 &&!RB2 && !RB1 && RB0)
{
PORTB=PORTB & 0x0F;
PORTB=PORTB | 0x60;
while(RB3 &&!RB2 && !RB1 && RB0);
//DelayMs(30);
}
//-------------------------------------------------------------------------


if(RB3 &&!RB2 && !RB1 && !RB0)
{
PORTB=PORTB & 0x0F;
PORTB=PORTB | 0x70;
while(RB3 &&!RB2 && !RB1 && !RB0);
//DelayMs(30);
}
//-------------------------------------------------------------------------

if(!RB3 &&RB2 && RB1 && RB0)
{
PORTB=PORTB & 0x0F;
PORTB=PORTB | 0x80;
while(!RB3 &&RB2 && RB1 && RB0);
//DelayMs(30);
}
//---------------------------------------------------------------------
if(!RB3 && RB2 && RB1 && !RB0)
{
PORTB=PORTB & 0x0F;
PORTB=PORTB | 0x90;
while(!RB3 &&RB2 && RB1 && !RB0);
//DelayMs(30);
}

//---------------------------------------------------------------------
if(!RB3 &&RB2 && !RB1 && RB0)
{
PORTB=PORTB & 0x0F;
PORTB=PORTB | 0xA0;
while(!RB3 &&RB2 && !RB1 && RB0);
//DelayMs(30);
}

//-------------------------------------------------------------------------

if(!RB3 &&RB2 && !RB1 && !RB0)
{
PORTB=PORTB & 0x0F;
PORTB=PORTB | 0xB0;
while(!RB3 &&RB2 && !RB1 && !RB0);
//DelayMs(30);
}

//---------------------------------------------------------------------
if(!RB3 &&!RB2 && RB1 && RB0)
{
PORTB=PORTB & 0x0F;
PORTB=PORTB | 0xC0;
while(!RB3 &&!RB2 && RB1 && RB0);
//DelayMs(30);
}

//-------------------------------------------------------------------------

if(!RB3 &&!RB2 && RB1 && !RB0)
{
PORTB=PORTB & 0x0F;
PORTB=PORTB | 0xD0;
while(!RB3 &&!RB2 && RB1 && !RB0);
//DelayMs(30);
}

//-------------------------------------------------------------------------

if(!RB3 &&!RB2 && !RB1 && RB0)
{
PORTB=PORTB & 0x0F;
PORTB=PORTB | 0xE0;
while(!RB3 &&!RB2 && !RB1 && RB0);
DelayMs(30);
}

//-------------------------------------------------------------------------

if(!RB3 &&!RB2 && !RB1 && !RB0)
{
PORTB=PORTB & 0x0F;
PORTB=PORTB | 0xF0;
while(!RB3 &&!RB2 && !RB1 && !RB0);
DelayMs(30);
}

//-------------------------------------------------------------------------


}
}
 
Last edited:
Is it really C18??Doesnt it have to be like this


#include<p18f242.h> and not #include "pic18.h"


And the config settings are done with # pragma as specified by Bill.

And its Delays.h not Delay.h and also there is no such function in C18 like DelayMS(may be you have made this header file your self)
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top