; This file is a basic code template for assembly code generation * ; on the PICmicro PIC12F675. This file contains the basic code * ; building blocks to build upon. * ; * ; If interrupts are not used all code presented between the ORG * ; 0x004 directive and the label main can be removed. In addition * ; the variable assignments for 'w_temp' and 'status_temp' can * ; be removed. If the internal RC oscillator is not implemented * ; then the first four instructions following the label 'main' can * ; be removed. * ; * ; Refer to the MPASM User's Guide for additional information on * ; features of the assembler (Document DS33014). * ; * ; Refer to the respective PICmicro data sheet for additional * ; information on the instruction set. * ; * ;********************************************************************** ; * ; Filename: xxx.asm * ; Date: * ; File Version: * ; * ; Author: * ; Company: * ; * ; * ;********************************************************************** ; * ; Files required: * ; * ; * ; * ;********************************************************************** ; * ; Notes: * ; * ; * ; * ; * ;********************************************************************** list p=12f675 ; list directive to define processor #include ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT ; '__CONFIG' directive is used to embed configuration word within .asm file. ; The lables following the directive are located in the respective .inc file. ; See data sheet for additional information on configuration word settings. ;***** VARIABLE DEFINITIONS w_temp EQU 0x20 ; variable used for context saving status_temp EQU 0x21 ; variable used for context saving ;********************************************************************** ORG 0x000 ; processor reset vector goto main ; go to beginning of program ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register ; isr code can go here or be located as a call subroutine elsewhere movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt ; these first 4 instructions are not required if the internal oscillator is not used main call 0x3FF ; retrieve factory calibration value bsf STATUS,RP0 ; set file register bank to 1 movwf OSCCAL ; update register with factory cal value bcf STATUS,RP0 ; set file register bank to 0 ; remaining code goes here ; initialisatie ; hier regelen even wat huishoudelijke zaken voor we gaan beginnen banksel CMCON ; ingebouwde comperator uitschakelen movlw B'00000111' ; zie datasheet voor meer informatie movwf CMCON banksel WPU ; ingebouwde pull-up weerstanden uitschakelen movlw 0x00 ; zie datasheet voor meer informatie movwf WPU banksel ADCON0 ; ingebouwde AD-converter uitschakelen movlw 0x00 ; zie datasheet voor meer informatie movwf ADCON0 counth EQU 0x20 ; adres 020 hex reserveren we om de waarde van ; variabele counth op te slaan count1 EQU 0x21 ; adres 021 hex reserveren we om de waarde van ; variabele countl op te slaan repetitions EQU 0x22 ; adres 022 hex reserveren we om de waarde van ; variabele repetitions op te slaan ; ========== hoofdprogramma ========== ; we gaan afwisslend LED1 en LED 7 laten branden ; om wat overzicht te bewaren zetten we het in subroutines ; onderstaand is het hoofdprogramma van waaruit telkens een routine ; aangeroepen wordt om een bepaalde taak uit te voeren start ; begin hoofdprogramma call LED1aan ; ga naar subroutine om LED1 aan te zetten call delay ; een tijdsvertraging ingebouwd omdat anders beide LED's ; tegelijk lijken te branden door de snelheid van de processor call LED7aan ; ga naar subroutine om LED7 aan te zetten call delay ; een tijdsvertraging ingebouwd omdat anders beide LED's ; tegelijk lijken te branden door de snelheid van de processor goto start ; ga naar begin hoofdprogramma ; ========== subroutines ========== ; ********** LED1 aan ********** ; GP0, 1, 2, 3 als ingang schakelen ; GP4 en 5 als uitgang schakelen LED1aan ; naam van subroutine banksel TRISIO ; ga naar BANK1 waarin TRISIO zich bevind movlw B'00001111' ; definieer in en uitgangen ; tel van rechts naar links, 0 als uitgang, 1 als ingang etc. movwf TRISIO ; schrijf IO definitie naar TRISIO banksel GPIO ; selecteer BANK0 waarin GPIO zich bevind movlw B'00000000' ; maak voor de zekerheid alle uitgangen 0 movwf GPIO ; we weten niet met welke status GPIO hier aankomt BSF GPIO,5 ; maak GP5 hoog return ; ********** einde LED1 aan ********** ; ********** LED7 aan ********** ; GP0, 1, 3, 5 als ingang schakelen ; GP2 en 4 als uitgang schakelen LED7aan ; naam van subroutine banksel TRISIO ; ga naar BANK1 waarin TRISIO zich bevind movlw B'00101011' ; definieer in en uitgangen ; tel van rechts naar links, 0 als ingang, 1 als ingang etc. movwf TRISIO ; schrijf IO definitie naar TRISIO banksel GPIO ; selecteer BANK0 waarin GPIO zich bevind movlw B'00000000' ; maak voor de zekerheid alle uitgangen 0 movwf GPIO ; we weten niet met welke status GPIO hier aankomt BSF GPIO,4 ; maak GP4 hoog return ; ********** einde LED7 aan ********** ; ********** universele vertraging ********** ; vul variable repetitions met D'01' (decimaal 01) voor elke 100 msec ; dus voor 1 seconde D'10' delay ; naam van subroutine movlw D'05' ; vul het W register met decimaal 5 voor 500 msec movwf repetitions ; schrijf dit naar de repetitieteller ; deze staat voor het aantal herhalingen van de 100 msec vertraging outerloop100ms ; start van buitenlus, wordt nu in dit geval 5 maal herhaald movlw D'200' ; vul het W register met decimaal 200 movwf counth ; schrijf dit naar counth middleloop100ms ; deze buitenlus wordt dus 200 maal herhaald movlw D'99' ; vul het W register met decimaal 99 movwf count1 ; schrijf dit naar countl innerloop100ms ; deze binnenlus wordt dus 99 maal herhaald nop ; geen instructie maar kost wel processortijd nop ; geen instructie maar kost wel processortijd decfsz count1,f ; trek 1 van countl af en sla als deze 0 is de volgende ; instructie over goto innerloop100ms ; countl is nog geen 0 dus gaan we de binnen lus nog maar eens doen nop ; geen instructie maar kost wel processortijd decfsz counth,f ; trek 1 van counth af en sla als deze 0 is de volgende ; instructie over goto middleloop100ms ; counth is nog geen 0 dus gaan we de middelste lus nog maar eens doen decfsz repetitions,f ; trek 1 van aantal herhalingen af en sla als deze 0 is de volgende ; instructie over goto outerloop100ms ; nog niet alle herhalingen gehad, dus het geheel nog een keer return ; het gewenste aantal herhalingen is doorlopen dus gaan we terug ; ********** einde universele vertraging ********** ; initialize eeprom locations ORG 0x2100 DE 0x00, 0x01, 0x02, 0x03 END ; directive 'end of program'