Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

AT89C51 C Programming..

Status
Not open for further replies.

ankithamirwasia

Newbie level 4
Joined
Apr 29, 2011
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,313
I am making a simple project using AT89C51 in which i make an LED glow when the ir sensor is taken over a black coloured surface and the LED switches off when taken over a white coloured surface. I need help with the C program for the micro controller . I am taking an input from port 1 bit 0 and giving an output on port 0 bit 7. My circuit is complete with a comparator which gives 0V for a black surface and +4.5V for a white surface and this is fed into port 1 bit 0. Can someone please give me the C code to implement the required task??
 

#include <REG51.H>
sbit IR_IP = P1^0;
sbit LED_OP = P1^7;

void main(void)
{
while(1)
{
if(IR_IP) LED_OP = 1; // [if Anode of LED is connedted IO of controller else change the led logic here]
else LED_OP = 0;
}
}
 
thank you so much..
could you also tell me the steps in programming it using UniPro programmer by any chance after i create the hex file in Keil. Cause my program is not getting stored for some reason.

I saved the code as a '.c' extension. Selected the micro controller as AT89C51 in Keil and then made the hex file by building it. Now what should i do in UniPro??
 

check if hex file is generated when you compile or not in the folder.
tell how unipro is connected to 8051 board, using serial cable or whiat kind of cable are you using....
 

i dont get any error..
after burning the program when i check the micro controller memory i cant find any code..
it stays completely blank..
 

#include <REG51.H>
sbit IR_IP = P1^0;
sbit LED_OP = P1^7;

void main(void)
{
while(1)
{
if(IR_IP) LED_OP = 1; // [if Anode of LED is connedted IO of controller else change the led logic here]
else LED_OP = 0;
}
}

I'm sorry but this doesnt work. LED glows all the time.
 

Measure the voltage at P1.0 [Input]... As per this program logic if input is HIGH, then making output HIGH else output LOW.... Check your circuit connection properly or else put your schematic here...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top