Posts

Showing posts from 2016

8051 microcontroller programming:Timers-interfacing Timer0 and Timer1 together

Image
Timers are one of the most important peripherals of 8051. There are two 16-bit counters present in 8051. It is controlled using TMOD register. G C/T M1 M0 G C/T M1 M0   The first four bits are for the Timer1 and the lower four bits are for the Timer0. G- Gate bit for timer1. 0-TR1 should be made high starting the timer. 1-INT1 and TR1 should be HIGH for starting the timer. C/T- Counter/Timer 0-Acts as timer .i.e. internal oscillator provides the clock. 1-Acts as counter .i.e. external crystal provides the clock. M1,M0- Mode selectors. M1 MO MODE FUNCTION 0 0 0 13-bit timer 0 1 1 16-bit timer 1 0 2 8-bit auto reload timer 1 1 3 Split timer Timer 1 in mode 2 is used for serial communication. Maximum count possible is in Mode-1, that is FFFF (66535). Delay(microseconds)=1.085*(F...

8051 microcontroller programming: Interfacing with push button and displaying the number of button presses

Image
This is a good practice question. PROGRAM: ORG 00H MOV 30H,#0C0H MOV 31H,#0F9H MOV 32H,#0A4H MOV 33H,#0B0H MOV 34H,#99H MOV 35H,#92H MOV 36H,#82H MOV 37H,#0F8H MOV 38H,#80H MOV 39H,#90H MOV 3AH,#088H MOV 3BH,#83H MOV 3CH,#0C6H MOV 3DH,#0A1H MOV 3EH,#86H MOV 3FH,#8EH MOV R0,#30H SETB P1.0 MOV P2,@R0 HERE: JB P1.0,HERE HERE1: JNB P1.0,HERE1 INC R0 MOV A,@R0 MOV P2,A SJMP HERE END

8051 microcontroller programming: Interfacing with push button and displaying the button pressed using Keil

Image
Displaying the number of the corresponding push button pressed on a seven segment display. This a good practice program. PROGRAM: ORG 00H BACK: JNB P1.0,ZERO JNB P1.1,ONE JNB P1.2,TWO JNB P1.3,THREE JNB P1.4,FOUR JNB P1.5,FIVE JNB P1.6,SIX JNB P1.7,SEVEN SJMP BACK ZERO: MOV P2,#0C0H SJMP BACK ONE: MOV P2,#0F9H SJMP BACK TWO: MOV P2,#0A4H SJMP BACK THREE: MOV P2,#0B0H SJMP BACK FOUR: MOV P2,#99H SJMP BACK FIVE: MOV P2,#92H SJMP BACK SIX: MOV P2,#82H SJMP BACK SEVEN: MOV P2,#0F8H SJMP BACK END

8051 microcontroller programming:Tutorial-Using DB in Keil

Image
DB is a very useful function, data tables can be stored directly into the ROM along with the program. Data stored in the ROM can be accessed by the instruction MOVC. Sample Program is given below. ORG 00H DB 30H MOV DPTR,#0000H MOVC A,@A+DPTR MOV DPTR,#2000H MOVX @DPTR,A END

8051 microcontroller programming:Interfacing ADC 0808 and displaying in decimal through LCD using Keil

Image
The output from ADC is binary, it is easier for the user if the output is in decimal. The output ranges from 00H to FFH. So in decimal it will be from 0 to 256. RS EQU P2.3 RW EQU P0.1 E EQU P0.0 ALE EQU P2.4 START EQU P2.6 EOC EQU P2.7 OE EQU P2.4 AA EQU P2.0 BB EQU P2.1 CC EQU P2.2 ORG 00H MOV A,#38H ACALL COMMAND MOV A,#0EH ACALL COMMAND LOOP: MOV A,#01H ACALL COMMAND MOV A,#80H ACALL COMMAND MOV P1,#0FFH SETB EOC CLR START CLR OE CLR ALE SETB AA CLR BB CLR CC ACALL DELAY SETB ALE ACALL DELAY SETB START ACALL DELAY CLR START CLR ALE WAIT: JB EOC,WAIT RESTART:JNB EOC,RESTART SETB OE ACALL DELAY MOV A,P1 CLR OE ACALL CONV SJMP LOOP COMMAND:ACALL READY MOV P3,A CLR RS CLR RW SETB E ACALL DELAY CLR E RET DISPLAY:ACALL READY MOV P3,A SETB RS CLR RW SETB E ACALL DELAY CLR E RET READY: SETB P3.7 SETB RW CLR RS BACK: CLR E ACALL DELAY SETB E JB P3.7,BACK RET DELAY: MOV ...

8051 microcontroller programming:Interfacing ADC 0808 and displaying using Seven segment displays with Keil

Image
Displaying the output from ADC is the most important aspect of interfacing an ADC with 8051. All the four ports are used. PORT0 :Lower nibble seven segment display. PORT1:ADC output. PORT2:   P2.0-ADD A   P2.1-ADD B   P2.2-ADD C   P2.4-ALE   P2.5-OE   P2.6-START   P2.7-EOC PORT3 :Higher nibble seven segment display. ORG 00H MOV 30H,#0C0H //COPY THE CODE FOR DISPLAING THE DIGITS TO THE SEVEN SEGMENT DISPLAY MOV 31H,#0F9H MOV 32H,#0A4H MOV 33H,#0B0H MOV 34H,#99H MOV 35H,#92H MOV 36H,#82H MOV 37H,#0F8H MOV 38H,#80H MOV 39H,#0B0H MOV 3AH,#088H MOV 3BH,#83H MOV 3CH,#0C6H MOV 3DH,#0A1H MOV 3EH,#86H MOV 3FH,#8EH ALE EQU P2.4 //ASSIGN PIN5 OF PORT2 FOR ALE (ADDRESS LATCH ENABLE) OF ADC START EQU P2.6 //ASSIGN PIN6 OF PORT2 FOR START OF ADC EOC EQU P2.7 //ASSIGN PIN7 OF PORT2 FOR EOC(END OF CONVERSION) OF ADC OE EQU P2.5 //ASSIGN PIN4 OF PORT2 FOR OE(OUTPUT ENABLE) OF ADC AA EQU P2.0 ...

8051 microcontroller programming:Tutorial-Fibonacci series in assembly with Keil

Image
Fibonacci series is also a good practice code: The sequence is: 1,1,2,3,5,8............. PROGRAM: ORG 00H MOV DPTR,#2000H MOVX A,@DPTR DEC A DJNZ A,LOOP2 INC DPTR MOV A,#01H MOVX @DPTR,A INC DPTR MOV A,#01H MOVX @DPTR,A END LOOP2: MOV R1,A INC DPTR MOV A,#01H MOVX @DPTR,A INC DPTR MOV A,#01H MOVX @DPTR,A LOOP1: DEC DPL MOVX A,@DPTR MOV R2,A INC DPTR MOVX A,@DPTR ADD A,R2 INC DPTR MOVX @DPTR,A DJNZ R1,LOOP1 END

8051 microcontroller programming:Tutorial-factorial in assembly with Keil

Image
Finding factorial is one of the basic programs. It's a good practice code. Factorial is given as: n!=n*(n-1)*(n-2)*..........................*1 PROGRAM: ORG 00H MOV DPTR,#2000H MOVX A,@DPTR MOV R0,A MOV A,#01H MOV B,A MOV R1,A LOOP: MUL AB MOV R5,B MOV B,A MOV A,R1 INC A MOV R1,A DJNZ R0,LOOP MOV A,R5 INC DPTR MOVX @DPTR,A MOV A,B INC DPTR MOVX @DPTR,A END

8051 microcontroller programming:Tutorial-Generating sequences-(0*1,1*2,2*3,......(n-1)*n)

Image
Generating a particular is some of the common needs for a programmer. Let us see how a sequence can be generated. Consider the sequence-0*1,1*2,2*3,3*4,..................,(n-1)*n, where is the input. PROGRAM: ORG 00H MOV DPTR,#2000H MOVX A,@DPTR MOV R0,A MOV A,#00H MOV R1,A LOOP: MOV A,R1 MOV B,A INC A MOV R1,A MUL AB INC DPTR MOVX @DPTR,A DJNZ R0,LOOP END

8051 microcontroller programming:Interfacing with ADC 0808 in assembly using Keil

Image
An ADC is a device which converts the analog input to digital. The most commonly used ADC is 0808, it is an 8 bit parallel ADC. It has 8 input channels.We can select which input to convert through channel selectors. CIRCUIT DIAGRAM: PROGRAM: ALE EQU P2.4 ;ASSIGN PIN5 OF PORT2 FOR ALE (ADDRESS LATCH ENABLE) OF ADC START EQU P2.6 ;ASSIGN PIN6 OF PORT2 FOR START OF ADC EOC EQU P2.7 ;ASSIGN PIN7 OF PORT2 FOR EOC(END OF CONVERSION) OF ADC OE EQU P2.5 ;ASSIGN PIN4 OF PORT2 FOR OE(OUTPUT ENABLE) OF ADC AA EQU P2.0 ;ASSIGN PIN0 OF PORT2 FOR AA(CHANNEL SELECT A) OF ADC BB EQU P2.1 ;ASSIGN PIN1 OF PORT2 FOR BB(CHANNEL SELECT B) OF ADC CC EQU P2.2 ;ASSIGN PIN2 OF PORT2 FOR CC(CHANNEL SELECT C) OF ADC RS EQU P2.3 ;ASSIGN PIN3 OF PORT2 FOR RS(REGISTER SELECT) OF LCD RW EQU P0.1 ;ASSIGN PIN1 OF PORT0 FOR ALE(ADDRESS LATCH ENABLE) OF LCD E EQU P0.0 ;ASSIGN PIN0 OF PORT0 FOR RW(READ/WRITE) OF LCD ORG 00H LOOP: MOV A,#38H...