programming microcontroller at89c51.docx
DESCRIPTION
Vyan. Programming Micro AT89C51TRANSCRIPT
Programming Microcontroller AT89C51
Microcontroller has a function as microprocessor. The different is simplicity of microcontroller that can stand alone with out any component such ADC and external memory. Microcontroller is a kind of integrated circuit that be packed as common IC. The main different is the ability to run the instruction code that is loaded at it's memory. On the other hand, microcontroller is completed with Arithmetic Logic Unit that can run arithmetic operations. With out a program that was loaded in it's memory, microcontroller can do nothing. Microcontroller AT89C51Microcontroller AT89C51 is a product of Atmel Corp, that belong to MCS51 microcontroller family. This microcontroller has a same architecture with microcontroller 8031, product of Intel Corp. The specification of microcontroller AT89C51 are stated below: - 8 bit data line- 4K Byte of flash memory - Maximum clock frequency is 24MHz- 128 Byte internal Memory - Four I/O port - Dual 16 bit timer/counter Registers of AT89C51Microcontroller AT89C51 has some registers, registers that explain in this tutorial are:- Accumulator- R0 - R7 Example of Simple Program Here are two simple listing program in assembly language, The used assembler is asm51.exe
Figure 1. At89c51 Application Circuit for running led and seven segment display.
- Running Led
Figure 2. A photograph of Running Led Circuit.
$mod51 org 00h jmp mulai ;program dimulai di sinimulai: mov r1, #05hloop: dec r1 mov a, #01h mov p1, a
call tundakiri:
rl a mov p1, a call tunda cjne a, #80h, kirikanan: rr a mov p1, a call tunda cjne a, #01h, kanan cjne r1, #00h, loop ljmp mulai ;tunda: mov r4, #02hulang: dec r4 mov r3, #0ffhtunda1: dec r3 mov r2, #0ffhtunda2:
dec r2 cjne r2, #00h, tunda2 cjne r3, #00h, tunda1 cjne r4, #00h, ulang retend
The registers that are used above are r1 to r4, and accumulator too. The port that is used to light on eight LEDs is P1. - Displaying a Number Using Seven Segment Display
Figure 3. A Photograph of Seven Segment Displaying Circuit.
$mod51 org 00h jmp mulai mulai: mov r6, #00h mov a, #00h
ulang: mov r6, p2 mov p1, r6 lcall tampil1 mov p2, #01000000b lcall tunda lcall tampil2 mov p2, #10000000b lcall tunda jmp ulang tampil1:mov a, #00h clr c mov b, #10 mov a, r6 div ab cjne a, #00h, ke_1 ljmp nol1ke_1: cjne a, #01h, ke_2 ljmp sijike_2: cjne a, #02h, ke_3 ljmp loro ke_3: cjne a, #03h, ke_4 ljmp telu ke_4: cjne a, #04h, ke_5 ljmp papatke_5: cjne a, #05h, ke_6 ljmp limake_6: cjne a, #06h, ke_7 ljmp enemke_7: cjne a, #07h, ke_8 ljmp pituke_8: cjne a, #08h, ke_9 ljmp woluke_9: cjne a, #09h, keluar ljmp sangakeluar: ret tampil2:mov a, #00h clr c mov a, b cjne a, #00h, ke_12 ljmp nolke_12: cjne a, #01h, ke_22 ljmp sijike_22: cjne a, #02h, ke_32 ljmp loro ke_32: cjne a, #03h, ke_42 acall telu
ke_42: cjne a, #04h, ke_52 ljmp papatke_52: cjne a, #05h, ke_62 ljmp limake_62: cjne a, #06h, ke_72 ljmp enemke_72: cjne a, #07h, ke_82 ljmp pituke_82: cjne a, #08h, ke_92 ljmp woluke_92: cjne a, #09h, keluar2 ljmp sangakeluar2:ret ; a ; f b ; g ; e c ; d ;0gfedcbanol1: mov p0, #00h retnol: mov p0, #00111111b retsiji: mov p0, #00000110b retloro: mov p0, #01011011b rettelu: mov p0, #01001111b retpapat: mov p0, #01100110b retlima: mov p0, #01101101b retenem: mov p0, #01111101b retpitu: mov p0, #00000111b retwolu: mov p0, #01111111b retsanga: mov p0, #01101111b ret tunda: mov r5, #255kurang: dec r5 cjne r5, #00h, kurang retend
The listing program above, has a function to display two binary datum that saved in r6. The used display are two seven segment common cathode LED. Datum at a segment to g are attached from P0.0 -P0.6. For sweeping digit once and second we use P2.7 and p2.8