![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Hi ET,
I am doing my Microcontroller course for the first time and have few difficulties nin writing C program for PIC16F877Program must read upper 4 switches connected to PORTB(SB4-SB7)and activate corresponding lamp connected to lower part of PORTB(LB0-LB3, respectively). Also -If switch SB7 is pressed, all four LB0-LB3 lamps should be ON as long as SB7 is pressed -If switch SB6 is pressed, all four LB0-LB3 lamps should flash ON and OFFwith 1 sec delay as long as SB6 is pressed I have written program but this is not working Char count=0; void main (void) { set_bit (STATUS,5); set_bit (STATUS,6); TRISB=0xF0; set_bit (STATUS, 5); if(COUNT>=0xF0) PORTB=0x00 else PORTB=0x0F; set_bit (STATUS,5); clear_bit (STATUS,6); while(1) { { PORTB=0x0F; delay_ms(1000); PORTB=0xF0; delay_ms(1000); } } Thanks Raaj |
|
|
|
|
|
|
(permalink) |
|
That code isn't even close to accomplish what you described. Did you really write this yourself? It's not reading any input?! See my comment below...
Code:
char count=0;
void main (void)
{
set_bit (STATUS,5);
set_bit (STATUS,6);
TRISB=0xF0;
set_bit (STATUS, 5);
PORTB=++COUNT; /* This is weird, what are you trying to do? */
if(COUNT>=0xF0)
PORTB=0x00
else
PORTB=0x0F;
set_bit (STATUS,5);
clear_bit (STATUS,6);
while(1)
{
PORTB=0x0F;
delay_ms(1000);
PORTB=0xF0;
delay_ms(1000);
}
}
__________________
Time is nature\'s way of keeping everything from happening at once. http://membres.lycos.fr/jrainville/ |
|
|
|
|
|
|
(permalink) | |
|
Quote:
For the first part of your assignment then a simple way to achieve this would be. PORTB = PORTB>>4 You can then go onto implement the rest of it. HTH Mike. P.S. it's not nice to change your code after someone Joel) has commented on it. |
||
|
|
|