Simple LED program in C

Status
Not open for further replies.

neelam29

New Member
DEAR ALL,

i am designing a simple project using pic16f876a and hitech c complier (MPLAB ) . i want to send a value on port b.this is the daigram and the code m sending.please check the code and help me find out the mistake.i have defined pic16f876 and oscillator type crystal in mplab.
byee

#include <pic.h>

main(void)
{
unsigned char i, j;

TRISB = 0; /* all bits output */
j = 0;
for( ; ; ) {
PORTB = 0xaa; /* SEND 10101010 */

}
}
 

Attachments

  • PIC1.JPG
    32.4 KB · Views: 232
for what i and j used for .? and what is the need of the infinite for loop ?
well i haven't used hitech c , but i think the code should set 0xAA on portb
 
mudassir_semiconductor said:
akg dont know mc programming, what is the diff in 0xaa and 0xAA r u making fool to nelam

There's no 'difference', but some compilers and assemblers are case sensitive, so one way might work and the other not work - you need to check your compiler to see if it's case sensitive.
 
I've never known a C compiler that cared about case in hex constants.

nit-picking aside, that program looks like it should work. the reason for the for loop is to prevent executing garbage when returning from main. he could just as well have done this
Code:
PORTB = 0xaa;
for(;;);
 
Last edited:
mudassir_semiconductor said:
akg dont know mc programming, what is the diff in 0xaa and 0xAA r u making fool to nelam
i didn't mean the case sensitive part .. look at what i asked. you misinterpreted the statement.
 
Last edited:
heh heh, maybe it's because there is no power or ground hooked up (missing from the schematic). Maybe the leds are in backwards. wrong crystal? maybe the chip isn't programmed. ...
 
Nothing wrong with your main code.
Most likely you have not set the config bits correctly.
Not having it hooked up right, osc not running, RESET pin held low, no Vdd & gnd, etc also possible.
 
reminds me of a problem I was helping a guy with. he was certain that his code was wrong. it turns out he never actually programmed the chip...

my bet is on backwards LEDs.
 
philba said:
my bet is on backwards LEDs.

Oooh that's a good one too.

Be sure to write back as to what the problem was. Some of us are keeping score at how often we were right.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…