200 likes | 347 Views
Micro-processor vs. Micro-controller. PIC16F877. 40pin DIP CMOS technology RISC CPU 35 single word instructions DC-20MHz clock DC-200ns instruction cycle. PIC 16F877. Clock/Pipeline. Program Memory/Stack. Instruction Set. W EQU H'0000' ; standard definitions
E N D
PIC16F877 • 40pin DIP • CMOS technology • RISC CPU • 35 single word instructions • DC-20MHz clock • DC-200ns instruction cycle
Instruction Set W EQU H'0000' ; standard definitions F EQU H'0001'; ...to avoid having to write numbers incf var,W ; W = var + 1, var is unchanged incf var,F ; var = var + 1, W is unchanged • Default destination • STATUS Register • Subtraction (Borrow Flag) addlw -2 sublw 2
Tool Chain (MPLAB/CCS) • Programming facilities • Pre-processor functions • Code checking/warning • Prepared include/library files • Debug without hardware • limited programming cycles • safety -- bugs may blow equipment • Debug with equipment • on-line view of register values help to track down problems.
Lab Exercise:Failing loop test #device PIC16F877 *=8 ADC=8 void main() { int c; for (c=9;c<=255;c++); } 0000 3000 movlw 0x0 0001 008A movwf 0xA 0002 2804 goto MAIN 0003 0000 nop 0004 0184 MAIN clrf 0x4 0005 301F movlw 0x1F 0006 0583 andwf 0x3 0007 3009 movlw 0x9 0008 00A1 movwf 0x21 0009 0AA1 incf 0x21 000A 2809 goto 0x9 000B 0063 sleep
Working loop test (1) #device PIC16F877 *=8 ADC=8 void main() { int c; for (c=9;c<=254;c++); } 0000 3000 movlw 0x0 0001 008A movwf 0xA 0002 2804 goto MAIN 0003 0000 nop 0004 0184 MAIN clrf 0x4 0005 301F movlw 0x1F 0006 0583 andwf 0x3 0007 3009 movlw 0x9 0008 00A1 movwf 0x21 0009 30FF movlw 0xFF 000A 0221 subwf 0x21,W 000B 1803 btfsc 0x3,0x0 000C 280F goto 0xF 000D 0AA1 incf 0x21 000E 2809 goto 0x9 000F 0063 sleep
Working loop test (2) #device PIC16F877 *=8 ADC=8 void main() { long c; for (c=9;c<=255;c++); } 0000 3000 movlw 0x0 0001 008A movwf 0xA 0002 2804 goto MAIN 0003 0000 nop 0004 0184 MAIN clrf 0x4 0005 301F movlw 0x1F 0006 0583 andwf 0x3 0007 01A2 clrf 0x22 0008 3009 movlw 0x9 0009 00A1 movwf 0x21 000A 08A2 movf 0x22 000B 1D03 btfss 0x3,0x2 000C 2811 goto 0x11 000D 0AA1 incf 0x21 000E 1903 btfsc 0x3,0x2 000F 0AA2 incf 0x22 0010 280A goto 0xA 0011 0063 sleep
Another loop Fails #device PIC16F877 *=8 ADC=8 void main() { int c; c=9; do{}while (c++ <= 255); } 0000 3000 movlw 0x0 0001 008A movwf 0xA 0002 2804 goto MAIN 0003 0000 nop 0004 0184 MAIN clrf 0x4 0005 301F movlw 0x1F 0006 0583 andwf 0x3 0007 3009 movlw 0x9 0008 00A1 movwf 0x21 0009 2809 goto 0x9 000A 0063 sleep
While Loop OK! #device PIC16F877 *=8 ADC=8 void main() { int c; c=9; do { } while (c++!=255); } 0000 3000 movlw 0x0 0001 008A movwf 0xA 0002 2804 goto MAIN 0003 0000 nop 0004 0184 MAIN clrf 0x4 0005 301F movlw 0x1F 0006 0583 andwf 0x3 0007 3009 movlw 0x9 0008 00A1 movwf 0x21 0009 0821 movf 0x21,W 000A 0AA1 incf 0x21 000B 00F7 movwf 0x77 000C 0A77 incf 0x77,W 000D 1D03 btfss 0x3,0x2 000E 2809 goto 0x9 000F 0063 sleep