180 likes | 379 Views
Design & Technology Foundation - Electronic Control (II) (Micro-controller Programming). By Jasper Wong email: icjwong@polyu.edu.hk. Micro-controller Programming. Winice 8051/8052 8051 in-circuit emulator. Micro-controller Programming.
E N D
Design & TechnologyFoundation - Electronic Control (II)(Micro-controller Programming) By Jasper Wong email: icjwong@polyu.edu.hk 8051c/jw
Micro-controller Programming • Winice 8051/8052 8051 in-circuit emulator 8051c/jw
Micro-controller Programming General features of a microprocessor development system: • Memory Mapping • Observation and modification of CPU resources • Observation and modification of memory • Compilation of application program • Execution of application program (such as Go, Step, Cycle) • To set breakpoints • To trace application program • To offer prototype interface • User friendly operation interface • Real-time emulation of CPU 8051c/jw
Micro-controller Programming Main features of the Winice System • To emulate 8051 family up to 16Mhz • Real-time emulation • 128k bytes emulation memory (64k program, 64k data memory) • Multi-function hardware breakpoints • Real-time trace and hardware qualify function • Logic analysis function • Use standard PC parallel/printer port interface • Programming ability • Multiprocessor emulation • Event triggering output function • Built-in symbolic debugger, high level language debugger 8051c/jw
Micro-controller Programming Integrated hardware and software suggested processes: • Use In-circuit emulator(ICE) emulation memory for application software • Disable interrupt function of your program • Survey the main program first • Testing the I/O function • Observe your interrupt program by using ICE and make sure its function is normal • Enable interrupt • Use trace or breakpoint function of ICE • After this process, program a CPU for testing 8051c/jw
Micro-controller Programming 8051 Emulator Window Environment 8051c/jw
Micro-controller Programming Three Debugging Windows: • Program Watch Window - user program display area Functions include breakpoint setting, dump program to file, program execute point, change display address, stepping into, stepping over and full speed program running • Register Watch Window - display all values of CPU registers • Memory Watch Window - displays the assigned memory area 8051c/jw
Micro-controller Programming • Training System (Winice emulator + training Kit) 8051c/jw
Micro-controller Programming • Training Kit 8051c/jw
Micro-controller Programming • Training Kit Circuit 8051c/jw
Micro-controller Programming 8051 Programming • Data Byte Movement MOV direct, #data ; data (direct) MOV Rn, #data ; data (Rn) MOV A, #data ; data (A) A 8-bit binary constant will move into a Special Function Register after execution of the first instruction. The second instruction will move a data into a particular register in the current selected Register Bank .The Accumulator will hold the value equal to #data after the instruction is executed. 8051c/jw
Micro-controller Programming • Light up a Green LED --- Move P1, #AA • Light up a Red LED --- Move P1, #55 8051c/jw
Micro-controller Programming • Read Switch Status Mov A, P0 Mov P1, A 8051c/jw
Micro-controller Programming • Bit Operation CLR bit ;0B (bit),set a bit to 0. SETB bit ;1B (bit),set a bit to 1. CPL bit ;(bit) (bit),complement of a bit. Turn off a buzzer SETB P3.4 SETB P3.5 Turn on a buzzer CLR P3.4 CLR P3.5 8051c/jw
Micro-controller Programming • Buzzer Circuit 8051c/jw
Micro-controller Programming • Address Operation DJNZ Rn, addr DJNZ direct, addr The first instruction will decrease the content of the Rn register by one, if the content of the Rn register is not equal to zero after the decrement, the program flow will jump to the address specified by "addr". If the content of the Rn register is equal to zero after decrement, the program flow will be continued without jumping. The second one will decrement the content of the RAM at address specified by "direct" by one. If the new value is not equal to zero, then the instruction on the address specified by "addr" will be executed, otherwise the program flow will be continued without jumping. The range for this jumping is limited to + 128 bytes. 8051c/jw
Micro-controller Programming • Arithmetic Operation ADD A, direct ; (direct)+(A) (A) ADD A, Rn ; (Rn)+(A) (A) ADD A, #data ; data+(A) (A) The value stored in "direct", the register Rn and the #data of the above instructions will ADD with the value in the Accumulator and the result is stored in the Accumulator. 8051c/jw
Micro-controller Programming • Logical Operation ANL A, Rn ; (A) (Rn) (A) ANL A, #data ; (A) data (A) ANL A, direct ; (A) (direct) (A) ANL direct, A ; (direct) (A) (direct) ANL direct, #data ; (direct) data (direct) All the above instructions work with binary data format. The first three instructions will store the result on the Accumulator, the last two instructions will store the result in the RAM memory at address shown in "direct" or Special Function Register. 8051c/jw