Showing posts with label microcontroller. Show all posts
Showing posts with label microcontroller. Show all posts

Friday, June 29, 2012

Blinking one LED with 8051

This is the first project regarding 8051 and of course one of the simplest, blinking LED using 8051. The microcontroller used here is AT89S51 In the circuit, push button switch S1, capacitor C3 and resistor R3 forms the reset circuitry. When S1 is pressed, voltage at the reset pin (pin9) goes high and this resets the chip. C1, C2 and X1 are related to the on chip oscillator which produces the required clock frequency. P1.0 (pin1) is selected as the output pin. When P1.o goes high the transistor Q1 is forward biased and LED goes ON. When P1.0 goes low the transistor goes to cut off and the LED extinguishes. The transistor driver circuit for the LED can be avoided and the LED can be connected directly to the P1.0 pin with a series current limiting resistor(~1K).  The time for which P1.o goes high and low (time period of the LED)  is determined by the program. The circuit diagram for blinking 1 LED is shown below.

Program :-

Using assembly

START: CPL P1.0
       ACALL WAIT  
       SJMP START

WAIT:  MOV R4,#05H
WAIT1: MOV R3,#00H
WAIT2: MOV R2,#00H
WAIT3: DJNZ R2,WAIT3
        DJNZ R3,WAIT2
        DJNZ R4,WAIT1
        RET

Using embedded C

#include<reg51.h>
void delay(unsigned int)
void main()
{
unsigned char a;
while(1)
{
p1^0=1;
delay(500);
p1^0=0;
delay(500);
}
void delay(unsigned int dtime) // generates  a delay of 1ms
{
unsigned int i,j;
for(i=0;i<dtime;i++)
for (j=0;j<1275;j++);
}
}
}

NOTE :-

Well it might look difficult with embedded C but making bigger programs are a lot more easier in embedded c then in assembly

Thursday, April 12, 2012

8051 Microcontroller Basic

AT89C51 is an 8-bit microcontroller and belongs to Atmel's 8051 family. ATMEL 89C51 has 4KB of Flash programmable and erasable read only memory (PEROM) and 128 bytes of RAM. It can be erased and program to a maximum of 1000 times.

In 40 pin AT89C51, there are four ports designated as P1, P2, P3 and P0. All these ports are 8-bit bi-directional ports, i.e., they can be used as both input and output ports. Except P0 which needs external pull-ups, rest of the ports have internal pull-ups. When 1s are written to these port pins, they are pulled high by the internal pull-ups and can be used as inputs. These ports are also bit addressable and so their bits can also be accessed individually.
Port P0 and P2 are also used to provide low byte and high byte addresses, respectively, when connected to an external memory. Port 3 has multiplexed pins for special functions like serial communication, hardware interrupts, timer inputs and read/write operation from external memory. AT89C51 has an inbuilt UART for serial communication. It can be programmed to operate at different baud rates. Including two timers & hardware interrupts, it has a total of six interrupts.

Pin Diagram: 
Pin Description: 


 Pin No
 Function
 Name
1
8 bit input/output port (P1) pins
P1.0
2
P1.1
3
P1.2
4
P1.3
5
P1.4
6
P1.5
7
P1.6
8
P1.7
9
Reset pin; Active high
Reset
10
Input (receiver) for serial communication
RxD
8 bit input/output port (P3) pins
P3.0
11
Output (transmitter) for serial communication
TxD
P3.1
12
External interrupt 1
Int0
P3.2
13
External interrupt 2
Int1
P3.3
14
Timer1 external input
T0
P3.4
15
Timer2 external input
T1
P3.5
16
Write to external data memory
Write
P3.6
17
Read from external data memory
Read
P3.7
18
Quartz crystal oscillator (up to 24 MHz)
Crystal 2
19
Crystal 1
20
Ground (0V)
Ground
21
8 bit input/output port (P2) pins
/
High-order address bits when interfacing with external memory
 P2.0/ A8
22
 P2.1/ A9
23
 P2.2/ A10
24
 P2.3/ A11
25
 P2.4/ A12
26
 P2.5/ A13
27
 P2.6/ A14
28
 P2.7/ A15
29
Program store enable; Read from external program memory
PSEN
30
Address Latch Enable
ALE
Program pulse input during Flash programming
Prog
31
External Access Enable;  Vcc for internal program executions
EA
Programming enable voltage; 12V (during Flash programming)
Vpp
32
8 bit input/output port (P0) pins
Low-order address bits when interfacing with external memory
 P0.7/ AD7
33
 P0.6/ AD6
34
 P0.5/ AD5
35
 P0.4/ AD4
36
 P0.3/ AD3
37
 P0.2/ AD2
38
 P0.1/ AD1
39
 P0.0/ AD0
40
Supply voltage; 5V (up to 6.6V)
Vcc