TNE019 Mikrodatorer F2 1 Memory organization Memory blocks: Program memory (flash-type) 16 kword (32 kbyte) (instruction 16 bit wide) PC Reset Data RAM 1536 byte (1.5 kbyte) Data EEPROM 256 byte
TNE019 Mikrodatorer F2 2 Program memory for instructions. Instruction are stored as 2 bytes or 4 bytes. Least Significant Byte, LSB, stored on even address. Program counter,pc, increments in step of 2.
TNE019 Mikrodatorer F2 3 Read/Write from program memory. Not only programcode for instructions in memory. * One byte can be read. * One block min 64 byte can be erased. * One block min 8 byte can be programmed Read/Write Ex: Read one word and save it in RAM. movlw addressx ;TBLPTRU,TBLPTRH,TBLPTRL movwf TBLPTRx tblrd*+ movf TABLAT,W movwf Value_even tblrd*+ movf TABLAT,W movwf Value_odd
TNE019 Mikrodatorer F2 4 Data memory in static RAM Divided into 16 banks each contain 256 byte. Two parts General Purpose Registers, GPR Special Function Registers, SFR Address for each register is 12 bit. Bank Select Register, BSR<3:0> holds the upper 4 bits of address. Select which bank to be accessed.
TNE019 Mikrodatorer F2 5 Access to data memory in RAM, direct addressing Direct addressing
TNE019 Mikrodatorer F2 6 Access to data memory in RAM, indirect addressing Indirect addressing There are 3 indirect addressing registers FSR0, FSR1 and FSR2 INDF0, INDF1 and INDF2 Example: Clear RAM in Bank1 lfsr FSR0,0x100 Next clrf POSTINCO btfss FSR0H,1 goto Next. POSTINCn autoincrement FSRn after access POSTDECn- autodecrement FSRn after access PREINn autoincrement FSRn before access
TNE019 Mikrodatorer F2 7 Access to data EEPROM Used to store changeable parameters Example: Write to memory Not direct mapped in registers, instead It is indirect addressed through SFR. Involved registers in SFR are EECON1, EECON2, EEDATA and EEADR Example: Read from memory movlw movwf bcf bcf bsf movf ee_data EEADR EECON1,EEPGD EECON1,CFGS EECON1,RD EEDATA,W movlw movwf movlw movwf bcf bcf bsf bcf movlw movwf movlw movwf bsf bsf.. bcf ee_adr EEADR ee_data EEDATA EECON1,EEPGD EECON1,CFGS EECON1,WREN INTCON,GIE H 55 EECON2 H AA EECON2 EECON1,WR INTCON,GIE EECON1,WREN
TNE019 Mikrodatorer F2 8 Input/Output Ports Port A, B, C, D and E Each port has 3 registers for its operation: TRIS (data direction reg) PORT (reads level of pins) LAT (output latch) Bits in TRIS register: 0 makes corresponding bit an output and 1 makes it an input. You have to take care for multiple function on most bits.
TNE019 Mikrodatorer F2 9 Loads on in-/output ports Connecting LED to ports. In which case is current max? Ex: Determine the resistor for max LED current of 15 ma.
TNE019 Mikrodatorer F2 10 Protection of ports Input pins is protected against voltage over V DD and below V SS with clamping diodes. To limit the current to ports you had to use a protection resistor Rx.
TNE019 Mikrodatorer F1 11 Tangentbord Ett antal slutande återfjädrande kontakter. Tangentborden är konstruerade för att lätt kunna avkodas. Knapparna är placerade i ett koordinatsystem av ledare (rader och kolumner). Tangentbord kan avkännas på olika sätt Radavkänningsmetoden Linjeomvändningsmetoden
TNE019 Mikrodatorer F2 12 Radavkänningsmetoden.
TNE019 Mikrodatorer F2 13 Linjeomvändningsmetoden
TNE019 Mikrodatorer F2 14 Tangentbord med många tangenter.
TNE019 Mikrodatorer F2 15 Annat exempel på tangentbordsavkodning
TNE019 Mikrodatorer F2 16 Kontaktstudsar
TNE019 Mikrodatorer F2 17 Timer modules Four 16-bit timers. Timer0 can be used as a timer or a counter. Internal or external clock. Counts up. Edge select for external clock. Overflow from FF to 00. ;Timer delay with fosc = 20 MHz movlw B 11000011 movwf T0CON movlw D 206 movwf TMR0L bcf INTCON,TMR0IF Loop btfss INTCON,TMR0IF goto Loop. ;Count pulses on bit 4 porta, T0CKI movlw B 11100001 movwf T0CON clrf TMR0L ;Some delay. movlw TMR0L movwf Puls
TNE019 Mikrodatorer F2 18 Timer0 Control Register
TNE019 Mikrodatorer F2 19 Timer Module 1,2 and 3 Besides working as timers or counters it is possible to use them in Capture mode (Timer 1 and Timer 3) Compare mode (Timer 1 and Timer 3) PWM mode (Pulse Width Modulation) (Timer 2) PWM period = [(PR2)+1]*4*T oscillator *TMR2 prescaler PWM duty_cycle = (CCPR1L:CCP1CON<5:4>)* T oscillator *TMR2 prescaler PWM resolution = (log(f oscillator /f PWM )/log(2)) bits