PIC micro14 Architecture Video... some important ideas (but not an exhaustive list!!)
Some dimensions:
8 bit data bus
14 bit instruction bus
13 bit PC
8 level stack
Addressing Modes:
1) Direct
7 bits of the instruction specify
a register. 7 bits --> 128 different 8-bit registers. But PIC
16f627/628 can address more registers. How ? Status register contains
two bits (RP0 and RP1) that can specify 4 different register banks. So
maximum theoretical RAM space is 4 x 128 = 512 .
2) Indirect
Use the FSR register for indirect
addressing. FSR register is 8 bits, one can use the IRP bit in the
status register for for 9 bit addressing. This gives an address space
of 512. Access is accomplished thru the INDF register. Example: clear
all registers from 0x20 to 0x7F
movlw 0x20
movwf FSR
loop clrf INDF
incf FSR,F
btfss FSR,7
goto loop
3) Immediate Addressing
Operand is in instruction. Typically , a 6 bit opcode and an 8 bit operand. Example:
movlw 0xF3
retlw 0xff
4) Absolute Address
Will write directly to the PC.
Examples include CALL and GOTO. 3 bit opcode and 11 bit absolute address
5) PC relative Address
Add an 8 bit offset to the 13 bit
PC. Ah....a problem. How to do this? First, write 5 bits to PCLATH (PC
Latch High), next write 8 bits to PCL. The write to PCL will write
PCLATH as well. Study example in video: 8 segment LED display.
A little bit of memory mapping:
Bank 0
Bank 1
0x00 indirect
0x80 indirect
0x01 TMR0
0x81 OPTION
0x02 PCL
0x82 PCL
0x03 STATUS 0x83 STATUS
0x04 FSR
0x84 FSR
0x05 PORTA 0x85 TRISA
0x06 PORTB 0x86 TRISB
Example code to set all of PORTB to output and turn on lights (note: you must have the proper include file for this to work)
bsf STATUS,RP0 ;select bank 1
movlw b'00000000' ;set PortB 8 outputs
movwf TRISA
bcf STATUS,RP0 ;select bank 0
movlw 0xff
movwf PORTB ; turn those lights on
According to the PIC data sheet, the chip we are using has
128 bytes of EEPROM Data Ram and 224 bytes of RAM. What's the difference ?