Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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
    PIC1.JPG
    32.4 KB · Views: 231
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:
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.

New Articles From Microcontroller Tips

Back
Top