The "other" projectThis is my second PIC project. It's a robotic t-shirt! If you can't work out what it does, ask me for a demonstration. |
; the 'other' project (c) Rob Geleit September 2007 ; Version 1.1 ; Comedy robotic t-shirt ; PIC16F676 ; Crystal frequency 3.2768MHz ;********************************************************************** list p=16f676 ; list directive to define processor #include <p16F676.inc> ; 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 & _XT_OSC ; '__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. RADIX dec ;***** VARIABLE DEFINITIONS w_temp EQU 0x20 ; variable used for context saving status_temp EQU 0x21 ; variable used for context saving pscale1 EQU 0x22 pscale2 EQU 0x23 position EQU 0x24 posnstore EQU 0x25 flags EQU 0x26 _st EQU 20 _en EQU 252 _md EQU 219 ;********************************************************************** ORG 0x000 ; processor reset vector goto start ; go to beginning of program ORG 0x004 ; interrupt vector location bcf PORTC,5 ; interrupt routine for single servo bcf INTCON,T0IF ; clear T0 interrupt retfie ; movwf w_temp ; interrupt routine for multiple servos ; movf STATUS,w ; movwf status_temp ; ; clrf PORTC ; ; movf status_temp,w ; movwf STATUS ; swapf w_temp,f ; swapf w_temp,w ; retfie start call init loop ;bsf ADCON0,1 ; start conversion bcf INTCON,GIE ; stop interrupts bsf PORTC,5 ; start 5V -> Servo ctrl movlw 0 ; wait for 1.696ms movwf TMR1L wait17 movlw 150 subwf TMR1L,W btfss STATUS,Z goto wait17 btfsc PORTC,0 goto special btfss flags,0 goto cont movfw posnstore movwf position cont btfsc PORTA,2 incf position,F btfsc PORTC,2 decf position,F bcf flags,0 movfw position sublw _st btfsc STATUS,Z incf position movfw position sublw _en btfsc STATUS,Z decf position rntr movfw position ; move position reg to TMR0 movwf TMR0 movlw 160 ; enable interrupts movwf INTCON movlw 0 ; wait 18ms movwf TMR1L ; PORTC,0 will be cleared by interrupt movwf TMR1H ; during this time wait18 movlw 9 subwf TMR1H,W btfss STATUS,Z goto wait18 goto loop special btfsc flags,0 goto alrdy movfw position movwf posnstore bsf flags,0 movlw _md movwf position alrdy incf position incf position incf position movfw position sublw _en btfss STATUS,Z goto rntr movlw _md movwf position goto rntr init bcf STATUS,RP0 ; bank 0 clrf PORTA ; reset io clrf PORTC movlw 7 ; disable comparator movwf CMCON movlw 32 ; disable interrupts, enable TMR0 interrupt movwf INTCON movlw 0 ; ADC off (left justify and AD on =1) movwf ADCON0 movlw 49 ; max prescale + turn on TMR1 movwf T1CON bsf STATUS,RP0 ; bank 1 movlw 4 ; RA2 is input movwf TRISA movlw 7 ; RC0-2 are inputs movwf TRISC movlw 0 ; No ADC pins movwf ANSEL movlw 96 ; slow AtoD movwf ADCON1 movlw 1 ; internal timer - 2x prescale (=0) movwf OPTION_REG bcf STATUS,RP0 ; bank 0 bsf PORTA,1 ; LED power (should have cut track!) movlw _st movwf position return END ; directive 'end of program'