Author Topic: programming ports (digital)  (Read 2367 times)

0 Members and 1 Guest are viewing this topic.

Offline junior000Topic starter

  • Full Member
  • ***
  • Posts: 59
  • Helpful? 0
programming ports (digital)
« on: February 01, 2008, 01:42:20 PM »
hi, i am using p18f4550 and c18 compiler
  i configured all the analog ports as digital i/o
  then for the input 1 on port RE0 the led1 has to glow
  but the led1 is always in OFF state and led2 in ON state.
   can anyone tell what is wrong with the code??
   it got built in the compiler


#include<stdlib.h>
#include<p18f4550.h>
#include<delays.h>
#define sw1 PORTEbits.RE0
void main()
{
  ADCON1 = 0b00001111; //configuring all analog ports as digital i/o
  TRISC = 0b00111111;  //led1 and led2 as output
  TRISE = 0b11111111;  //all PORTE bits as digital input
  while(1)
   {
       if(sw1==1) //if portRE0==1 then switch on led1
       {
        PORTC = 0b10000000;
       }
       else if(sw1==0) //else switch on led2
       {
       PORTC = 0b01000000;
       }
       
   }
}
« Last Edit: February 02, 2008, 08:54:10 AM by junior000 »
view my tutorials at


www.myfirstbot.blogspot.com

Offline hazzer123

  • Supreme Robot
  • *****
  • Posts: 460
  • Helpful? 3
Re: help!
« Reply #1 on: February 01, 2008, 03:22:06 PM »
Try using LATC instead of PORTC.
Imperial College Robotics Society
www.icrobotics.co.uk

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: help!
« Reply #2 on: February 02, 2008, 12:11:50 AM »
Howdy

Offline ed1380

  • Supreme Robot
  • *****
  • Posts: 1,478
  • Helpful? 3
Re: help!
« Reply #3 on: February 02, 2008, 12:31:17 AM »
« Last Edit: February 02, 2008, 12:32:36 AM by ed1380 »
Problems making the $50 robot circuit board?
click here. http://www.societyofrobots.com/robotforum/index.php?topic=3292.msg25198#msg25198

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: help!
« Reply #4 on: February 02, 2008, 04:07:24 AM »
oh damnn i got bad burn :o sorry i couldnt resist doing this.
« Last Edit: February 02, 2008, 04:23:35 AM by SmAsH »
Howdy

 


Get Your Ad Here

data_list