Tutorial 03 - Assembler Timing diagrams (LO3)
With reference to the timing diagram in Figure 01, write an assembly code compatible with
PIC16F microcontroller to clock in the given 4 bits of data 1110. Instead of focusing on 10ms
and 100ms delays, write the delay function using a delay inside another delay method and load
both delays with 0xFF.
Figure 1
; PIC16F877A Configuration Bit Settings
; Assembly source line config statements
; CONFIG
CONFIG FOSC = EXTRC ; Oscillator Selection bits (RC oscillator)
CONFIG WDTE = OFF ; Watchdog Timer Enable bit (WDT disabled)
CONFIG PWRTE = OFF ; Power-up Timer Enable bit (PWRT disabled)
CONFIG BOREN = OFF ; Brown-out Reset Enable bit (BOR disabled)
CONFIG LVP = OFF ; Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is
digital I/O, HV on MCLR must be used for programming)
CONFIG CPD = OFF ; Data EEPROM Memory Code Protection bit (Data EEPROM code protection
off)
CONFIG WRT = OFF ; Flash Program Memory Write Enable bits (Write protection off; all program
memory may be written to by EECON control)
CONFIG CP = OFF ; Flash Program Memory Code Protection bit (Code protection off)
// config statements should precede project file includes.
#include <xc.inc>
;--------initialising-------------
PSECT start, CLASS = CODE, DELTA=2
start:
PAGESEL MAIN
GOTO MAIN
delay1 equ 0x20
delay2 equ 0x21
PSECT CODE, DELTA=2
;---------end initialising-------------
BCF STATUS, 6 ;
BSF STATUS, 5 ; Select Bank 1
;MOVLW 0x06 ; Configure all pins as digital
;MOVWF ADCON1 ; set all pins as digital inputs
CLRF TRISB ; Set RA<3:0> as inputs
BCF STATUS, 5 ; Bank0
;Initialising
MAIN:
BSF PORTB, 1 ;CS CS HIGH
BCF PORTB, 2 ;DIN
BCF PORTB, 3 ;CLK
CALL delay_start
BCF PORTB, 1 ;CS CS LOW
;END initialisation
CALL delay_start
;BIT 1 - (1 DIN)
BSF PORTB, 2 ;DIN
CALL delay_start
BSF PORTB, 3 ;CLK
CALL delay_start
BCF PORTB, 3 ;CLK
;BIT 2 - (0 DIN)
BCF PORTB, 2 ;DIN
CALL delay_start
BSF PORTB, 3 ;CLK
CALL delay_start
BCF PORTB, 3 ;CLK
;BIT 3 - (1 DIN)
BSF PORTB, 2 ;DIN
CALL delay_start
BSF PORTB, 3 ;CLK
CALL delay_start
BCF PORTB, 3 ;CLK
;BIT 4 - (0 DIN)
BCF PORTB, 2 ;DIN
CALL delay_start
BSF PORTB, 3 ;CLK
CALL delay_start
BCF PORTB, 3 ;CLK
CALL delay_start
BSF PORTB, 1 ;CS CS HIGH
goto MAIN
delay_start:
DECFSZ delay1
goto delay_start
MOVLW 0XFF
MOVWF delay1
DECFSZ delay2
goto delay_start
MOVLW 0XFF
MOVWF delay2
return
END start