Skip to main content

Posts

Showing posts from 2012

P89V51RD2 Interfacing with the UART Serial Communication

P89V51RD2 Interfacing with the UART Serial Communication Description                     Interfacing the UART Serial Communication with the P89v51rd2 Micro controller, with the baud rate of 9600bps. The Source code and Simulator Model of this Communication is listed Below. Source : #include <reg51.h> unsigned char var; unsigned char var1; void Serial_Init() {     TMOD = 0x20;     SCON = 0x50;     TH1  = 0xFD;     TR1   = 1;       } void Transmit_Char(unsigned char x) {     SBUF =  x;     while(!TI)     {     ;        }     TI = 0; } void Transmit_String(unsigned char *s) {     unsigned char i;     while((s[i]) != 0)     {         Transmit_Char(s[i]);         i++;     } } char Rcv() {         while(!RI)     {;}     RI = 0;     return SBUF; } void delay(unsigned int i) {     unsigned int j,k;     for(j=0;j<=i;j++)     {         for(k=0;k<256;k++);     } } void main(void) {     unsigned char r;     Serial_Init();     while(1)     {         Transmit_String("He
Interfacing The 7 Segment Display with 8051 Micro Controller           The AT 89c51 Micro Controller is interfacing with The 6 Digit 7 Segment Display, The Number of counts is incremented with the external INT0 Interrupt, and the input pin witch is connected with the port 3.4 id used to reset the count value.         Here the source code and the Screen Shot of the Proteus Simulator Model is added wit this. Source Code: #include <reg51.h> sbit clear = P3^4; unsigned char code DSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90, 0xff}; //unsigned char code Scan_BITs[]={0x20,0x10,0x08,0x04,0x02,0x01}; unsigned char code Scan_BITs[]={0x01,0x02,0x04,0x08,0x010,0x20}; unsigned char data Buffer_Counts[]={0,0,0,0,0,0}; unsigned int Count=0; void DelayMS(unsigned int x) {     unsigned char t;     while(x--)     {         for(t=0;t<120;t++);     } } void Show_Counts() {     unsigned int i;     Buffer_Counts[3] = Count / 1000;     Buffer_Counts[2] = Count %
P89V51RD2 Interfacing with DS1307 RTC           The DS1307 RTC IC I nterfacing with P89V51RD2 Micro Controller use of the KEIL IDE, and proteus simulator. The source code and thhe screen short of simulator model are attached with this.              This interfacing is done by the I2C Communication between the Micro Controller and DS1307 RTC. Source Code: #include <reg51.h> #include <stdio.h> sbit SCL = 0x90; // SCL for I2C sbit SDA = 0x91; // SDA for I2C volatile unsigned char DS1307_WA=0xD0; volatile unsigned char DS1307_RA=0xD1; unsigned char Rdata; unsigned char sec1,min1,hour1,date1,month1,year1,d,l,m,j,i; unsigned char sec[20],min[2],hour[2],ch1; unsigned char RTCDateTime[15]; unsigned char Buf[20]; void Serial_Init() {     TMOD = 0x20;     SCON = 0x50;     TH1  = 0xFD;     TR1  = 1;     TI   = 1;     RI   = 0;       } void delay(unsigned int i) {     unsigned int j,k;     for(j=0;j<=i;j++)     {         for(k=0;

ADC interfacing with 8081

Interfacing the AD0803 to the 8051 micro controller       This is the parallel port connector to the micro controller. The adc reading is transmitted to the serial port. Code: #include <reg51.h> #include <stdio.h> #define     adc_port    P1 sbit     rd = P2^0; sbit    wr = P2^1; sbit    cs = P2^2; sbit    intr = P2^3; //unsigned int adc; float adc1; void serial_init() {     TMOD = 0x20;     SCON = 0x50;     TH1  = 0xFD;     TR1  = 1;     TI   = 1;     RI   = 0;       }                    void delay(unsigned int i) {     unsigned int j,k;     for(j=0;j<=i;j++)     {         for(k=0;k<256;k++);     } } void adc_conv() {     cs = 0;     wr = 0;     wr = 1;     cs = 1;     while(intr); } void adc_read() {     cs = 0;     rd = 0;     adc1 = adc_port;     delay(1);     cs = 1;     rd = 1; } void main() {     serial_init();     printf("Hello World\n");     delay(5);     while(1)     {         adc_conv();         //printf("Hello\n");         adc_read

8051 Interfacing with Input Switch

Hear the interfacing of general input device with P89V51RD2 controller        when ever the input enabled that time the output connected to the port 1 of MSB will be high. Code: #include <reg51.h> //sbit switch1 = P1^1; void delay() {     unsigned int i,j;     for(i=0;i<=256;i++)     {         for(j=0;j<=10000;j++);     } } void main(void) {         //P1 = 0xfe;     delay();     while(1)     {         if(P1==0xfe)         {             P1 = 0xf0;             delay();         }     } }

LED with 8051

1: LED with 8051 #include <reg51.h> //sfr P1 = 0x90; //sfr P3 = 0xB0; void delay(unsigned int i) {     unsigned int j,k;     for(j=0;j<=i;j++)     {         for(k=0;k<256;k++);     } } void main(void) {     unsigned int i,j;     P1 = 0xff;     P3 = 0xff;     while(1)     {         P1 = 0x01;         delay(4000);         for(i=0;i<=10;i++)         {                P1 = P1 << 1;                delay(4000);         }         //P1 = 0x00;         delay(4000);         P1 = 0x80;         delay(4000);         for(j=0;j<=10;j++)         {             P1 = P1 >> 1;             delay(4000);         }                } }

LED Blinking with 8051 Microcontroller

#include <reg51.h> sbit Led0=P1^0; void delay(unsigned int i) {     unsigned int j,k;     for(j=0;j<=i;j++)     {         for(k=0;k<256;k++);     } } void main(void) {     P1 = 0xff;     while(1)     {         Led0 = 0;         delay(5);         Led0 = 1;         delay(5);     } }

Interfacing UART with 8051

The interfacing of serial communication (UART) with 8051 micro controller, with the baud rate of 9600bps.  Code: #include <reg51.h> #include <stdio.h> unsigned char c; void Serial_Init() {     TMOD = 0x20;     SCON = 0x50;     TH1  = 0xFD;     TR1  = 1;     TI   = 1;     RI   = 0;       } void delay(unsigned int i) {     unsigned int j,k;     for(j=0;j<=i;j++)     {         for(k=0;k<256;k++);     } } void main(void) {     Serial_Init();     printf("Hello World \n");     while(1)     {                 delay(5);         c = getchar();         delay(5);         //putchar(c);         delay(5);            }                    } Design Proteus: