; ; Do a poor job of emulating the Student ID ; CPU operation INCLUDE "p16f873.inc" ; Register Usage CBLOCK 0x020 ; registers start after special registers odd,out ; reserve space for two byte variables ENDC __CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC ; C Program equivalent ; ; unsigned char odd, out ; ; ; odd = 0; ; do { ; if (odd == 0) { ; out = 4; /* even sequence */ ; out = 8; ; out = 0; ; out = 2; ; out = 8; ; } else { ; out = 5; /* odd sequence */ ; out = 7; ; out = 1; ; out = 9; ; } ; } while (1); /* infinite loop */ org 0 ; ; odd = 0; ; clrf odd ; odd <- 0, do not assume '0' value of register ; value after reset ; bsf odd,0 ; uncomment this line to test odd seq ; do ; if (odd == 0) ; top btfsc odd,0 ; skip next instruction if bit 0 is '0' goto odd_seq ;start even sequence ; out = 4; movlw 4 ; w <- 4 movwf out ; out <- w ; out = 8; movlw 8 ; w <- 8 movwf out ; out <- w ; out = 0; movlw 0 ; w <- 0 movwf out ; out <- w ; out = 2; movlw 2 ; w <- 8 movwf out ; out <- w ; out = 8; movlw 8 ; w <- 8 movwf out ; out <- w goto top ; loop forever ;; start odd sequence odd_seq ; out = 5; movlw 5 ; w <- 5 movwf out ; out <- w ; out = 7; movlw 7 ; w <- 7 movwf out ; out <- w ; out = 1; movlw 1 ; w <- 1 movwf out ; out <- w ; out = 9; movlw 9 ; w <- 9 movwf out ; out <- w goto top ; loop forever end