AT89S51 Microcontroller As Downloader Circuit (AMDC)

This is one of the memorable projects of control engineering practicum in my school at that time in 2009, precisely in SMKN 2 Yogyakarta. This material was compiled together with 2 of my close friends, namely 10) Oki Yuditya Richi Pratama 3AV2, 33) Zulki Adzani Sidiq Fathoni 3AV2, and myself 26) Wawan Chahyo Nugroho 3AV2.

Substance:

  1. Making PCB
  2. Assembling the AT89S51 microcontroller components
  3. Write program and download to AT89S51 microcontroller
  4. Results of downloading the program that has been practiced

1. Making PCB

By using Protel PCB Designer software, we can create a layout and at the same time create its layout. This is what makes it easier for us to work in planning a PCB.

As for how to install the software, we can use the following guide: 

  1. Open the master protel 27 advanced PCB in the folder. 
  2. Click the setup section. 
  3. Wait for the installation options to appear and click install. 
  4. The destination directory display appears, click OK. 
  5. Then a question display will appear, click yes and wait for the installation process. 
  6. Once completed, the README display will appear, click the cross in the upper right corner (close). 
  7. To open the software, select advanced PCB. 
  8. Then the access code display will appear, click the access code. 
  9. To get the code, open the file SERIALNO -- copy code. 
  10. Move to toolbar view by pasting the file. 
  11. Perform testing by clicking test. 
  12. The last step, click OK, then the software can be used.

1.1 Creating a PCB Design for Area Boundary Display 

  1. Open Advanced PCB. 
  2. Select new page on the file menu line. 
  3. Create an area boundary, by selecting keep out layer in the layer options. 
  4. Specify the track, pad, and grid sizes in the current menu. 
  5. Create an area boundary measuring 7 cm x 10 cm.

1.2 Creating a PCB Design Bottom Border View (Layout)

  1. Select the bottom layer as a mark to create the layout. 
  2. Determine the desired track, pad and grid size via the current menu line. 
  3. Start designing.

To create a path on the copper layer, first:

  1. Create a design with a computer using the "PROTEL27 ADVANCED PCB" software.   
  2. Then printed and photocopied "XEROX" using transparency/mica.   
  3. The photocopy result is attached to the copper layer on the PCB and then ironed with medium heat. The goal is for the ink to stick to the copper.  
  4. The next process is to dissolve the unused layer with Ferric Chloride + sufficient water. 
  5. The ink is cleaned using steelwool 
  6. Drilling for component legs, before drilling, mark a point first with a nail to make drilling easier. 
  7. Coat the copper track with gondorukem + thinner solution. Wait until dry.


Fig.1.2 Bottom view of PCB

1.3 Creating a Top View PCB (Component Layout) 

  1. To select and display components, you can go through the librarycomponent menu bar.
  2. Then the browse libraries display will appear, there you can display the desired components by clicking display, and can move them to the work page by clicking place. 
  3. Make layout arrangements according to plan.

Top view PCB manufacturing steps:

  1. Create a design with a computer using the software "PROTEL27 ADVANCED PCB".
  2. Then printed and photocopied "XEROX" using transparency/mica.
  3. The photocopy result is attached to the top layer of the PCB and then ironed with medium heat. The goal is for the ink to stick to the top surface.


Fig.1.3 PCB top view

2. Assembling the AT89S51 Microcontroller Components 

In assembling the downloader components, the following tools and materials are required:

Tool:

  1. 40W electric soldering iron
  2. Multimeter
  3. Cutting pliers and clamping pliers

Material:

1. PCB downloader AT89S51

2. components which include: 

  • IC AT89S51 ............................ 1 piece 
  • IC 7805 .................................... 1 piece 
  • Elco 1000uf/16v ...................... 1 piece 
  • Elco 10 uf/16v ......................... 1 piece 
  • 20pf capacitor ......................... 2 pieces 
  • Crystal 3-33MHz ...................... 1 piece 
  • Resistor 10K ........................... 1 piece 
  • Resistor 2201.......................... 7 pieces 
  • Led ..........................................17 pieces 
  • Microswitch .............................1 piece 
  • ON/OFF switch .......................1 piece 

3. tin


Fig.2.1 AT89S51 downloader circuit


Fig.2.2 AT89S51 downloader (Top View)


Fig.2.3 AT 89S51 downloader (Bottom View)

2.1 Installing Amphenol With Data Cable 

In installing ampenol with data cable, a tool called tanggem is needed to press the ampenol lock so that it is tightly installed. How to install ampenol: 

  1. Place the data cable on top of the amphenol.
  2. Insert the clamp, then tighten it with a clamp.
  3. The data cable is bent, the lock is installed and then tightened with a clamp.


Fig.2.4 amphenol installation scheme

2.2 Installing Amphenol With Data Cable and DB25 

The installation of the data cable with DB25 must be adjusted to the port (name) on the circuit. Because if an error occurs, it will not be possible to download.


Fig.2.5 DB25 front view


Fig.2.5 DB25 installation scheme from the rear

2.3 Installing the USB Cable in the Microcontrol Circuit

Inside the USB cable there are 4 cables of different colors, namely red, black, white, and green. For installation on the microcontroller circuit, only 2 cables are needed, namely:

  • Red as power supply (+)5v 
  • Black as ground

2.4 Installing the Switch to Download the Program 

The switch is installed according to the circuit diagram. If the switch is connected (ON) then the circuit works. If it is used for a program/to download then the switch position must be disconnected (OFF). If in the connected position the download process cannot run.

3. Writing Program and Download to AT89S51 Microcontroller 

3.1 How to Write a Program with Assembler Language 

Physically, the work of a microcontroller can be explained as a cycle of reading instructions stored in memory. The microcontroller determines the address of the program memory to be read, and performs the process of reading data in memory. The data read is interpreted as an instruction. The instruction address is stored by the microcontroller in a register, known as the program counter. This instruction is for example an arithmetic program involving 2 registers. The facilities available in an assembly program are very minimal, unlike in a high-level programming language where everything is ready to use. The writer of the assembly program must determine everything, determine the location of the program he wrote in the program memory, create constant data and constant tables in the program memory, create variables used to work in the data memory and so on.

How to write a program in assembly language: 

  1. First install "win8051"
  2. Open the "8051 IDE" software 
  3. Click "file" then select "new"
  4. Start writing programs.

The general form of assembly program is as follows:

3.2 How to Convert Software

  • The program is written first using assembly language and saved.
  • Click the icon that looks like a stack of paper.

  • If the program is correct then the word "error" shows 0.
  • The program has been converted into Hex form.
  • The program is ready to be downloaded to the microcontroller circuit.

3.3 How to Download to AT89S51 Microcontroller Circuit 

  1. Connecting the DB25 cable to the computer
  2. Write the program in "8051 IDE" then convert it to Hex form.
  3. Open the IspPgm.exe program
  4. Then it will appear
  5. Click "open file" then look for the program you wrote earlier
  6. Select the program in Hex format. Click "open"
  7. Click "write" and the download process appears. The program is successfully downloaded if the download process is OK.

3.4 How to Download to AT89S51 Microcontroller Circuit from File 

  1. Connecting DB25 cable to computer 
  2. Open the program "IspPrg.exe" 
  3. In Isp-Flash Programmer click "open file". 
  4. Search for the program to be downloaded in .hex format 
  5. Click "open" the selected program 
  6. Click "write" on Isp-Flash Programmer. The download process is running. The program has been downloaded successfully.

4. Results of downloading programs that have been successfully implemented 

4.1 Program-1 Output flip-flop at P0

;------------------------
;   flip-flop di port 0
;------------------------
org 0h nop

mulai:
mov   p0,#00001111b
call     delay
mov   p0,#11110000b
call     delay
jmp    mulai

;------------------------
;       delay
;------------------------
delay:
mov r0,#0ffh

delay1:
mov r1,#0ffh

delay2:
nop
djnz r1,delay2
djnz r0,delay1
ret
end

4.2 Program-2 Flip-flop variations using P0 and P2

;---------variasi led----------

org 0h nop go:
mov p0,#11000000b
mov p2,#11000000b
call delay
mov p0,#00110000b
mov p2,#00110000b
call delay
mov p0,#00001100b
mov p2,#00001100b
call delay
mov p0,#00000011b
mov p2,#00000011b
call delay
mov p0,#00000011b
mov p2,#00000011b
call delay
mov p0,#00001100b
mov p2,#00001100b
call delay
mov p0,#00110000b
mov p2,#00110000b
call delay
mov p0,#11000000b
mov p2,#11000000b
call delay
mov p0,#00000000b
mov p2,#00000000b
call delay
mov p0,#10000000b
mov p2,#10000000b
call delay
mov p0,#01000000b
mov p2,#01000000b
call delay
mov p0,#00100000b
mov p2,#00100000b
call delay
mov p0,#00010000b
mov p2,#00010000b
call delay
mov p0,#00001000b
mov p2,#00001000b
call delay
mov p0,#00000100b
mov p2,#00000100b
call delay
mov p0,#00000010b
mov p2,#00000010b
call delay
mov p0,#00000001b
mov p2,#00000001b
call delay
mov p0,#00000001b
mov p2,#00000001b
call delay
mov p0,#00000010b
mov p2,#00000010b
call delay
mov p0,#00000100b
mov p2,#00000100b
call delay
mov p0,#00001000b
mov p2,#00001000b
call delay
mov p0,#00010000b
mov p2,#00010000b
call delay
mov p0,#00100000b
mov p2,#00100000b
call delay
mov p0,#01000000b
mov p2,#01000000b
call delay
mov p0,#10000000b
mov p2,#10000000b
call delay
mov p0,#11111111b
mov p2,#11111111b
call delay
jmp go

;-----------delay------------

delay: mov R0,#0FFH
delay1: mov R1,#0FFH

delay2: nop
djnz R1,delay2
djnz R0,delay1
ret
end

4.3 Program-3 Output with 7 segments on P0

;----------7 segment---------
org 0h

nop
start:
mov p3,#11000000b
call delay
mov p3,#11111001b
call delay
mov p3,#10100100b
call delay
mov p3,#10110000b
call delay
mov p3,#10011001b
call delay
mov p3,#10010010b
call delay
mov p3,#10000010b
call delay
mov p3,#11111000b
call delay
mov P3,#10000000b
call delay
mov p3,#10010000b
call delay
mov p3,#10000000b
call delay
mov p3,#11111000b
call delay
mov p3,#10000010b
call delay
mov p3,#10010010b
call delay
mov p3,#10011001b
call delay
mov p3,#10110000b
call delay
mov p3,#10100100b
call delay
jmp start

;----------delay------------
delay: mov r1,#09h
delay1: mov r2,#0ffh
delay2: mov r3,#0ffh
delay3: nop
djnz r3,delay3
djnz r2,delay2
djnz r1,delay1
ret
end

4.4 Press P3.0 led on press P3.1 led on P0 turns off

;- BAB3_09.ASM -------------------------------------------------------------------
;
; Simulasi penekanan tombol pd P3.0 untuk menghidupkan
; dan P3.1 untuk mematikan LED pada Port 1
;
;---------------------------------------------------------------------------------
ORG  0H
MULAI:
       MOV  A,P3
       CJNE A,#0FEH,TERUS
       MOV P2,#00000000B
       MOV P0,#11111111B
       SJMP MULAI
TERUS:
       CJNE A,#0FDH,MULAI
       MOV P0,#00000000B
       MOV P2,#11111111B
       SJMP MULAI

;-----------------7$egmant----------------------
start:
mov p3,#00001000b
call delay
mov p3,#11101110b
call delay
mov p3,#10010100b
call delay
mov p3,#11000100b
call delay
mov p3,#11100010b
call delay
mov p3,#11000001b
call delay
mov p3,#10000001b
call delay
mov p3,#11101100b
call delay
mov P3,#10000000b
call delay
mov p3,#11000000b
call delay
mov p3,#10100000b
call delay
mov p3,#10000000b
call delay
mov p3,#10011001b
call delay
jmp start

b:
mov p3,#10011001b
call delay
mov p3,#10000000b
call delay
mov p3,#10100000b
call delay
mov p3,#11000000b
call delay
mov P3,#10000000b
call delay
mov p3,#11101100b
call delay
mov p3,#10000001b
call delay
mov p3,#11000001b
call delay
mov p3,#11100010b
call delay
mov p3,#11000100b
call delay
mov p3,#10010100b
call delay
mov p3,#11101110b
call delay
mov p3,#00001000b
jmp b

;--------delay-----------
delay:  mov r1,#04h
delay1: mov r2,#0ffh
delay2: mov r3,#0ffh
delay3: nop
djnz r3,delay3
djnz r2,delay2
djnz r1,delay1
ret
end

Hope this is useful & happy learning!

ISP Programming 89Sxxx Microcontroller AT89S51

This ISP programmer can be used either in in system programming mode or in stand alone mode for ATMEL ISP ICs.

Hardware

This programmer circuit can be made in a very simple way. You only need an IC that is used as a 74244 buffer. Connect this circuit to the printer/LPT port to program the target circuit.

| No | Component              | Discription     |
|----|------------------------|-----------------|
| 1  | Connector DB 25        |                 |
| 2  | 6 Parallel Cable       | about 0.5 meter |
| 3  | Connector Header 6 pin |                 |
| 4  | House Connector DB 25  |                 |
| 5  | 74LS244                |                 |
| 6  | PCB                    | about 5 x 5 cm  |


Figure T.1. AT89S Programmer


Figure T.2. Top View AT89S Programmer


Figure T.3. Bottom View AT89S Programmer

Download Schematic and PCB Layout of Programmer Circuit

Design with EAGLE 4.01 program


Figure T.4 Schematic Diagram Programmer with LPT Connection

Memory Organization

All 8051 devices have separate address spaces for program memory and data memory, as shown in Figure 1.1. and Figure 1.2. The logical separation of program and data memory allows data memory to be accessed with 8-bit addressing, which can be quickly stored and manipulated by an 8-bit CPU. In addition, 16-bit data memory addressing can also be generated through the DPTR register. Program memory (ROM, EPROM and FLASH) can only be read, not written. Program memory can be up to 64K bytes. In the 89S51, 4K bytes of program memory are on the chip. To read external program memory, the microcontroller sends the PSEN (program store enable) signal.


Figure 1.1. Block diagram of the 8051 microcontroller

Data memory (RAM) occupies a separate address space from program memory. In the 8051 family, the lowest 128 bytes of data memory are on the chip. External RAM (maximum 64K bytes). In accessing External RAM, the microcontroller sends RD (read) and WR (write) signals.


Figure 1.2. 8051 Microcontroller Memory Architecture

Memory Program

Figure 1.2 shows a map of the bottom of program memory. After reset the CPU starts executing from location 0000H. As shown in Figure 1.3, each interrupt is assigned to a specific location in program memory. An interrupt causes the CPU to jump to the location where a specific service is to be performed.

External Interrupt 0, for example, is located at location 0003H. If External Interrupt 0 is to be used, then the service routine must be started at location 0003H. If this interrupt is not used, this service location can be used for various purposes as Program Memory.


Figure 1.3. Interrupt Map of the 8051 microcontroller

Memory Data

Figure 1.2 shows the internal and external data memory space of the 8051 family. The CPU generates the RD and WR signals required during external RAM access. The internal data memory is mapped as shown in Figure 1.2. The memory space is divided into three blocks, referred to as the lower 128 bytes, the upper 128 bytes and the SFR space.

Internal data memory addresses are always one byte wide. Direct addressing above 7Fh will access one memory address, and indirect addressing above 7Fh will access a different address. Thus, Figure 1.4 shows the upper 128 bytes and the SFR space occupy the same address block, namely 80h to FFh, which are actually physically separate. The lower 128 bytes of RAM are grouped into several blocks, as shown in Figure 1.5. The bottom 32 bytes of RAM are grouped into 4 banks, each consisting of 8 registers.

The program instructions to call these registers are named as R0 to R7. Two bits in the Program Status Word (PSW) can select which register bank to use. The use of registers R0 to R7 will make programming more efficient and shorter, when compared to direct addressing.


Figure 1.4. Internal data memory


Figure 1.5. The bottom 128 bytes of internal RAM

All of the lower 128 bytes of RAM can be accessed using either direct or indirect addressing. The upper 128 bytes can only be accessed indirectly, Figure 1.6.


Figure 1.6. The top 128 bytes of internal RAM.

Special Function Register

A memory map called the special function register ( SFR ) space is shown in the following figure. Note that not all of these addresses are occupied, and unoccupied addresses are not allowed to be implemented. Read accesses to these addresses will produce random data, and write accesses will produce unclear effects.

Accumulator

ACC is the accumulator register. The mnemonic for this accumulator specific instruction can be simply abbreviated as A.

Register B 

Register B is used during multiplication and division operations. In addition to the above purposes, this register can be used as a free register.

Word Status Program

The PSW register consists of program status information which is detailed in Table 1.1.

Stack Pointer

The stack pointer register has a data width of 8 bits. This register will be incremented before data is stored during push and call execution. While the stack can be anywhere in RAM. The stack pointer starts at address 07h after reset. This causes the stack to start at location 08h.

Data Pointers

Data Pointer (DPTR) consists of upper byte (DPH) and lower byte (DPL). This function is intended to store 16-bit data. Can be manipulated as a 16-bit register or two stand-alone 8-bit registers.


Figure 1.7. SFR Map

Ports 0, 1, 2 and 3

P0, P1, P2 and P3 are the SFRs occupied by Ports 0, 1, 2 and 3. Writing a logic 1 to a bit of a port SFR (P0, P1, P2 or P3) causes the corresponding port output pin to be in a logic high '1' condition. And vice versa.

Serial Data Buffer 

The serial buffer is actually two separate registers, the transmit buffer and the receive buffer. When data is loaded into the SBUF, it goes to the transmit buffer and is held for transmission. When data is taken from the SBUF, it comes from the receive buffer.

Register Timer

The register pairs (TH0, TL0) and (TH1, TL1) are 16-bit counting registers for Timer/Counter 0 and 1, respectively.

Register Control 

The IP, IE, TMOD, TCON, SCON, and PCON registers consist of control and status bits.

Word Status Program

PSW or Program Status Word contains status bits related to the condition or state of the microcontroller CPU at that time. PSW is located in the SFR space location (see Figure 1.9, with the address location D0h). In this PSW we can monitor several statuses including: carry bit, auxiliary carry (for BCD operations), two register bank selector bits, overflow flag, a parity bit and two status flags that can be defined by yourself. The carry bit can also be used for arithmetic operations, and can also be used as a universal accumulator for several boolean operations.

Table 1.2.1 Word Status Program

| MSB |    |    |     |     |    |   | LSB |
|-----|----|----|-----|-----|----|---|-----|
| CY  | AC | F0 | RS1 | RS0 | OV | - | P   |
| BIT   | SYMBOL | FUNCTION                                                                                                                                        |
|-------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| PSW.7 | CY     | Carry flag.                                                                                                                                     |
| PSW.6 | AC     | Auxilliary Carry flag. (For BCD operations.)                                                                                                    |
| PSW.5 | F0     | Flag 0. (Available to the user for general purposes.)                                                                                           |
| PSW.4 | RS1    | Register bank select control bit 1. Set/cleared by software to determine working register bank. (See Note.)                                     |
| PSW.3 | RS0    | Register bank select control bit 0. Set/cleared by software todetermine working register bank. (See Note.)                                      |
| PSW.2 | OV     | Overflow flag.                                                                                                                                  |
| PSW.1 | -      | User-definable flag.                                                                                                                            |
| PSW.0 | P      | Parity flag. Set/cleared by hardware each instruction cycle to indicate an odd/even number of “one” bits in the Accumulator, i.e., even parity. |

Bits RS0 and RS1 can be used to select one of four register banks as shown in table 19.2. The parity bit can be used to find out the number of logical '1's in the accumulator: P=1 if the accumulator has an odd number of logical '1's, and P=0 if the accumulator has an even number of logical '1's. The other two bits PSW1 and PSW5 can be used for various purposes

Table 1. 2. Bank account address

| RS1 | RS0 | Bank | Address RAM |
|-----|-----|------|-------------|
| 0   | 0   | 0    | 00 h - 07 h |
| 0   | 1   | 1    | 08 h - 0F h |
| 1   | 0   | 2    | 10 h - 17 h |
| 1   | 1   | 3    | 18 h - 1F h |

Post a Comment

Previous Next

نموذج الاتصال