Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

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??
 

kandhu26

Member level 5
Joined
Sep 7, 2009
Messages
93
Helped
13
Reputation
26
Reaction score
12
Trophy points
1,288
Location
chennai / bangalore
Activity points
1,856
#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;
}
}
 

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
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??
 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,146
Reputation
4,298
Reaction score
2,087
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,097
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....
 

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 dont get any error..
after burning the program when i check the micro controller memory i cant find any code..
it stays completely blank..
 

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
#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.
 

kandhu26

Member level 5
Joined
Sep 7, 2009
Messages
93
Helped
13
Reputation
26
Reaction score
12
Trophy points
1,288
Location
chennai / bangalore
Activity points
1,856
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.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top