; Max Heise, 19.02.2002, 1450, - Angelegt als Beispielprogramm ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Beschreibung: ; Programm hat RB0 als Ausgang und RA2 als Eingang. Ist Eingang RA2 HIGH ; wird Ausgang RB0 auch HIGH gesetzt. Ist RA2 Low wird RB0 auch LOW gesetzt. ; Later I added capcam and pwm code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Config fuer IDE und Assembler LIST P=16F628, R=DEC __CONFIG H'3FF1' ; XT,WDOG OFF ; 11 1111 1111 0001 __IDLOCS H'F055' ; 1111 0000 0101 0101 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Include include "p16f628.inc" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Codebeginn org 0x00 goto Init org 0x04 Isr retfie Init bcf STATUS, RP1 bsf STATUS, RP0 ; sel bank 1 bcf TRISB, 0 ; RB0 is output bcf STATUS, RP0 ; sel bank 0 ; from the doc setup for porta clrf PORTA movlw 0x07 movwf CMCON ; setup for capcom module, 10.3.3 in the doc, p. 67 ;make CCP1 an output bcf STATUS, RP1 bsf STATUS, RP0 ; sel bank 1 bcf TRISB, 3 ; RB3==CCP1 is output bcf STATUS, RP0 ; sel bank 0 ;setup Timer2 movlw 0x07 movwf T2CON ;set PWM Period movlw 0xFF bsf STATUS, RP0 ; sel bank 1 movwf PR2 ; PR2=0xFF bcf STATUS, RP0 ; sel bank 0 ; => PWM signal with 1,22 KHz ; configure CCP1 module for PWM operation movlw 0x3C ; 0x30 to set the two LSB bits of the PWM duty cycle to 1, ; 0x0C to set PWM operation of CCP1 module movwf CCP1CON ; for test purposes I use two duty cycles: ; 1/4 and 3/4 ; 00 0000 0000b = 0d ; 00 1111 1111b = 255d = 1/4 = default ; 01 1111 1111b = 511d = 1/2 ; 10 1111 1111b = 767d = 3/4 ; 11 1111 1111b = 1023d ; 8 MSB Bits in CCPR1L: ; 0011 1111 = 0x3F ; 1011 1111 = 0xBF call PWM1_4 ; start main loop forever goto Loop PWM1_4 movlw 0x3F movwf CCPR1L retlw 0 PWM3_4 movlw 0xBF movwf CCPR1L retlw 0 Unsetpin bcf PORTB, 0 call PWM1_4 retlw 0 Setpin bsf PORTB, 0 call PWM3_4 retlw 0 LElse ;btfsc PORTB, 0 ; do not clear PORTB<0> if it is already cleared call Unsetpin goto Loop ; if PORTA<2> eq 0 set PORTB<0> ; else if PORTA<2> eq 1 clear PORTB<0>, this is the default Loop btfsc PORTA, 2 goto LElse ;btfss PORTB, 0 ; do not set PORTB<0> if it is already set call Setpin goto Loop end