0% found this document useful (0 votes)
24 views3 pages

C Code for AT89C51 with LCD1602

The document provides code for programming an 89C51 microcontroller using Keil uVision. It includes functions for converting a number to digits, delaying with a timer, and continuously displaying an incrementing number on LEDs.

Uploaded by

Muhammad Umair
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

C Code for AT89C51 with LCD1602

The document provides code for programming an 89C51 microcontroller using Keil uVision. It includes functions for converting a number to digits, delaying with a timer, and continuously displaying an incrementing number on LEDs.

Uploaded by

Muhammad Umair
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

C Code for Programming 89C51 Using Keil uVision

#include <reg51.h>

// delay with digit multi-plexing.. char min_MSB; char min_LSB; sbit portBit = P2^0; sbit mybit=P2^1; // FUnction to convert two digit number to the resective digits for [Link] min_LSBand min_MSB..

void convert_min(int number) { min_MSB = number / 10; min_LSB = number %10;

void delay_hundred() { //char min_LSB; //char min_MSB; char millisec;

//int number = 85; for (millisec=1;millisec <=10;millisec++) { //Turn first LED on.. P3 = min_MSB;

portBit =0; mybit = 1;

// Wait 5 milliseconds delay(); // Turn second LED on P3 = min_LSB; portBit = 1; mybit = 0;

// Wait 5 milliseconds.. delay(); }

delay() // timer of 1 sec { int d;

for(d=0;d<=1;d++) { TMOD=0x01; TL0=0xFD; TH0=0x04B; TR0=1; // start timer. while(TF0==0); // run until TF turns to 1 TR0=0; // stop timer TF0=0; // reset the flag } } void main(void) { //char min_MSB,min_LSB; int number = 35; while(1) { convert_min(number); delay_hundred(); number++; if(number >99) number = 0; } }

You might also like