Discussion in "PIC Microcontroller Discussion" started by    jimmymax2020    Mar 4, 2008.
Tue Mar 04 2008, 07:50 pm
#1
i having problem of my work with input from portA (controls the descending count from 16 to 0) to the output portB (dispaly the binary out by turning on the led)....

i want to get input state from port A( on/off), if on the down counter start from letting all 4 LED's and soon, then the program loop itself back after all Led is off (or count zero)... if the state if off ( it holds the Led's state )....

here is my work program....


void main() {
  int i=0; 
  PORTB = 0;
  TRISB = 0;           // PORTB is output
  TRISA = 1;           // PORTA is input

  do {
  if (PORTA != 0x01)
            i++;
  Delay_ms(1000);
  switch (i) {
  case 1: PORTB = 0x0F;
  case 2: PORTB = 0x0E;
  case 3: PORTB = 0x0D;
  case 4: PORTB = 0x0C;
  case 5: PORTB = 0x0B;
  case 6: PORTB = 0x0A;
  case 7: PORTB = 0x09;
  case 8: PORTB = 0x08;
  case 9: PORTB = 0x07;
  case 10: PORTB = 0x06;
  case 11: PORTB = 0x05;
  case 12: PORTB = 0x04;
  case 13: PORTB = 0x03;
  case 14: PORTB = 0x02;
  case 15: PORTB = 0x01;
  case 16: PORTB = 0x00;
}
  Delay_ms(1000);
  } while (1);
}


using mikroC compiler.... it display some error...

how can i solve this porblem???????.....



[ Edited Tue Mar 04 2008, 07:55 pm ]
Tue Mar 04 2008, 07:56 pm
#2
may i know what error your are getting?
Wed Mar 05 2008, 12:12 am
#3
Well I just copy-pasted your code in MicroC and its compiling fine without errors.
So start a new project,select the proper controller and default configuration.....should compile without problems.
Wed Mar 05 2008, 11:27 am
#4
thnks... it was an error of setting the clock..... now i have finish compiling it with a new project...

my problem now is that no output was generated when i start to on the portA after i put it to the ciruit board.....
so i developed another program.....

void main ()
	{
  int i=0;
	while(1) // loop forever //
	{
	TRISB=0;
	TRISA=1;
          if (PORTA != 0x01)
                  i++;
  if (i=1)
  {delay_ms(1000);
   PORTB = 0x0F;
   delay_ms(1000);
  }
  if (i=2)
  {delay_ms(1000);
   PORTB = 0x0E;
   delay_ms(1000);
  }
  if (i=3)
  {delay_ms(1000);
   PORTB = 0x0D;
   delay_ms(1000);
  }
  if (i=4)
  {delay_ms(1000);
   PORTB = 0x0C;
   delay_ms(1000);
  }
  if (i=5)
  {delay_ms(1000);
   PORTB = 0x0B;
   delay_ms(1000);
  }
  if (i=6)
  {delay_ms(1000);
   PORTB = 0x0A;
   delay_ms(1000);
  }
  if (i=7)
  {delay_ms(1000);
   PORTB = 0x09;
   delay_ms(1000);
  }
  if (i=8)
  {delay_ms(1000);
   PORTB = 0x08;
   delay_ms(1000);
  }
  if (i=9)
  {delay_ms(1000);
   PORTB = 0x07;
   delay_ms(1000);
  }
  if (i=10)
  {delay_ms(1000);
   PORTB = 0x06;
   delay_ms(1000);
  }
  if (i=11)
  {delay_ms(1000);
   PORTB = 0x05;
   delay_ms(1000);
  }
  if (i=12)
  {delay_ms(1000);
   PORTB = 0x04;
   delay_ms(1000);
  }
  if (i=13)
  {delay_ms(1000);
   PORTB = 0x03;
   delay_ms(1000);
  }
  if (i=14)
  {delay_ms(1000);
   PORTB = 0x02;
   delay_ms(1000);
  }
  if (i=15)
  {delay_ms(1000);
   PORTB = 0x01;
   delay_ms(1000);
  }
  if (i=16)
  {delay_ms(1000);
   PORTB = 0x00;
   delay_ms(1000);
   i=0;
  }

  }
}


i have compile this without error and it thus work in counting down (binary)...
when i input on(or 1) to portA..... but then it continues to count down.... my main objective is to control the output if i input signal to portA.... if not it holds the last state......

is there a problem with my new code ?


[ Edited Wed Mar 05 2008, 09:53 pm ]
Wed Mar 05 2008, 10:07 pm
#5
instead of writing this

if (PORTA != 0x01)


write

if (PORTA & 0x01 !=  0x01)


move the following statements out of while(1) loop because they are to be configured only once at the starting of main program.

TRISB=0;
TRISA=1;


I really don't know why aren't you getting any kind of error or something.. coz your if statements are wrong..

instead of
if (i=14)

you have to write
if (i==14)

for all if statements... Please make the changes and try again
Thu Mar 06 2008, 04:59 am
#6
i have compiled the changes you give... i have also tested in my circuit..... i just make the code:

if (PORTA & 0x01 != 0x00)

to satisfy the circuitry connection........

thanks....

i really appreciate the help..... :-)
Thu Mar 06 2008, 04:59 pm
#7
you're welcome!
so is it working now

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am
Richardrit
Tue Apr 23 2024, 09:54 am
HenryLaf
Mon Apr 22 2024, 03:50 pm
bleradrar
Mon Apr 22 2024, 06:38 am
ppu-pro_ka
Sun Apr 21 2024, 07:39 pm
Infewow
Sun Apr 21 2024, 06:30 pm
HumanTak
Sun Apr 21 2024, 12:26 pm