How To Load Program For At89c51 Projects

12/30
84

How To Load Program For At89c51 Projects

Posted in:

Simple and Free Electronicsengineering mini projects for electronics students. New Electronics mini projects topics for ECE,EEE,and Instrumentation students. Design of transformerless capacitor power supply. It is very simple and low cost solution to use capacitor dropper power supply in mains powered circuits.

Simple Two digit Calculator with 8051(89c51,89c52) Microcontroller. Calculator Takes two Single digits and an Operator as input and produces Output.

How To Load Program For At89c51 Projects

The operations supported by our Calculator are Addition, Subtraction, Negation & Division. Hardware requirements • One 89c52 or 89c51 microcontroller • Bread board or PCB (Making Circuit) • 16x2 lcd (Displaying Text) • 4x4 keypad (Taking Input) • Potentiometer (For setting lcd contrast) • Crystal(11.0592 MHz) Code Explanation Read the explanation carefully because it covers all the important points of the code and every statement is briefly explained. We assume that you are already familiar with c/c++ language syntax. If you don't than first take some tutorials of c/c++ programming and familiarize your self with c/c++ programming language syntax. Starting from the beginning, the first line of the code. Don't forget to include reg51.h header file to your every project that contains an 8051(89c51,89c52) microcontroller in it. This header file is very important. Keil compiler checks this header file in your code first.

If it is present compiler compiles your code, absence of this header file will lead to an error. Next some functions declarations.

Functions • void lcdcmd(unsigned char) ---- Sending COMMANDS to lcd. (If you dont know about commands just click the word) • void lcddata(unsigned char) ---- Sending DATA to lcd.

(If you dont know about just click the data word) • void MSDelay(unsigned int) ---- Generating Delay. • void disp_num(float num) ---- Displaying number on lcd after calculation. • int get_num(char ch) ---- Turning Character to Number • void lcdinit() ---- Initializing lcd chipset driver.

(click the link to see what it means ) • char scan_key(void) ---- Scanning a number from keypad. Than some character arrays are declared. The strings in them are displayed on 16x2 lcd during the calculator working. They're actually communicating with user, asking for inputs. Then i am using internal memory registers of 8051(89c51,89c52) Microcontroller the sfr's. Sfr's are direct memory locations to ports, registers and Timers etc. Sfr ldata=0xA0 is accessing Port-2 of microcontroller.

0xA0 is Sfr to Port-2. Manual For Creative Model Makers Wood. Now ldata is a variable that is pointing to Port-2 of microcontroller. Then some pins are declared. Lcd is Controlled by Port-3 pins# 5,6,7.

Lcd data pins are connected to Port-2 of Microcontroller. Port-1 is Scanning rows and coulombs of 4x4 keypad. ​Main Function I put the main function body in continuous while loop, in order to run the calculator for ever.

Lcdinit() function is initializing the lcd chipset driver with some necessary lcd commands (don't understand just click the link and you will have a good tutorial on it ). Than in while loop I am printing the string on lcd ENTER 1 NO =. Enter the number of your desire from keypad. Key=scan_key() statement is scanning key that you presses on the keypad. Scan_key() function returns a character that you pressed on keypad. K2=get_num(key) is converting the returned key from scan_key() function in a digit.

Scan_key() is reading the key as character. W203 Subwoofer Install. To perform arithmetic operation on the key we have to convert it in number. Get_num(key) is doing this work for us.

Then lcddata() function is printing the character on lcd and lcdcmd (0x01) command clears all the contents of lcd. Than the next string prints on lcd saying operator =. You have to enter the operator and all the previous steps are repeated.

Than the next string appears saying Enter 2 no= Just enter the no. Now you see a switch statement it is making decision if the operator you entered is + it will go for disp_num(K1+k2) function by adding the two number you just entered. For - operator it will go for negation and for other operators it will for them.

Sending commands and data to lcd is very import function its brief detail is available. Than delay function to put some delay in the process it is very important.

One can understand it when running the embedded code in hardware equipment's. Scan_key() function is explained on the following link. The disp_num() function is displaying our calculated number on 16x2 lcd. Now how it is working? First i am converting my float num in integer by numb=(int)num.

Then I am checking if num is less than 0 or if it is negative. If number is negative i multiplied it with -1 and make it positive. Then sending - sign on lcd because the value calculated is in - form. Than if value is grater than 10 i am finding ten digit by dividing numb/10 now if tendigit not equal to 0 than display it on lcd. Lcddata(tenthdigit+0x30) you people are thinking what does it mean.

Actually when I divide numb/10 the value returned to TEnthdigit is in ASCII form because TenthDigit is a character variable so to make a ASCII value to character just add 0x30 or 48 in it because these are the values from where the digits starts. Than for unit digit numb-TenthDigit*10 it will give us the unit digit in ASCII form to make it value add 0x30 in it. If you don't add 0x30(hexadecimal) or 48(decimal) to it Then the lcd will show some special characters.The starting characters of ASCII Table. Than decimal value is calculated and it is also printed on lcd using the same method. Just copy the code made the hardware circuit burn the code in 8051(89c51,89c52) microcontroller and check your creation.