free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
jimmymax2020
Tue Mar 04 2008, 06:20AM
 User Offline
Registered Member #6427
Joined: Tue Mar 04 2008, 05:55AM

Posts: 4
Thanked 0 times in 0 posts
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....


CODE:
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, 06:25AM ]

Back to top


Ajay
Tue Mar 04 2008, 06:26AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3753
Thanked 696 times in 655 posts
may i know what error your are getting?

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


sashijoseph
Tue Mar 04 2008, 10:42AM

 User Offline
Registered Member #5870
Joined: Mon Feb 04 2008, 06:26PM

Posts: 554
Thanked 124 times in 117 posts
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.

Let there be music........
Back to top


jimmymax2020
Tue Mar 04 2008, 09:57PM
 User Offline
Registered Member #6427
Joined: Tue Mar 04 2008, 05:55AM

Posts: 4
Thanked 0 times in 0 posts
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.....

CODE:
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, 08:23AM ]

Back to top


Ajay
Wed Mar 05 2008, 08:37AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3753
Thanked 696 times in 655 posts
instead of writing this

CODE:
if (PORTA != 0x01)


write

CODE:
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.

CODE:
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
CODE:
if (i=14)

you have to write
CODE:
if (i==14)

for all if statements... Please make the changes and try again

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


jimmymax2020
Wed Mar 05 2008, 03:29PM
 User Offline
Registered Member #6427
Joined: Tue Mar 04 2008, 05:55AM

Posts: 4
Thanked 0 times in 0 posts
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.....

Back to top


Ajay
Thu Mar 06 2008, 03:29AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3753
Thanked 696 times in 655 posts
you're welcome!
so is it working now

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems