Friends
I have been reading and referencing from Nigel tutorials and would like to know where am I making a mistake?
LIST p=16F628 ;tell assembler what chip we are using
include "P16F628.inc" ;include the defaults for the chip
ERRORLEVEL 0, -302 ;suppress bank selection messages
__config 0x3D18 ;sets the configuration settings (oscillator)
cblock 0x20 ;start of general purpose registers
count
KM Equ 0
org 0x0000
movlw 0x07
movwf CMCON ;turn comparators off
Initialise clrf count
clrf PORTA
clrf PORTB
SetPorts bsf STATUS, RP0 ;select bank 1
MOVLW B'00000110'
MOVWF TRISB
bcf STATUS, RP0 ;select bank 0
call SER_INIT
CHECK call Rcv_RS232 ;check receive data
xorlw 'B'
btfss STATUS, Z ;is data 'B'?
goto CHECK ;if not, goto CHECK
goto KM_ON ;if yes. goto KM_ON
KM_ON bsf PORTB, KM ;ON
goto CHECK
:Hardware USART Serial Routines
SER_INIT
BSF STATUS, RP0 ;select bank 1
MOVLW d'25' ;9600 baud @ 4 Mhz Fosc +0.16% err
MOVWF SPBRG
MOVLW b'00100100' ;BRGH = 1
MOVWF TXSTA ;enable Async Transmission, set brgh
BCF STATUS, RP0 ;select bank 0
MOVLW b'10010000'
MOVWF RCSTA ;enable Async Reception
RETURN
XMIT_RS232 btfss PIR1, TXIF ;xmit buffer empty?
GOTO XMIT_RS232 ;no, wait
MOVWF TXREG ;now send
RETURN
Rcv_RS232 BTFSS PIR1, RCIF ;check for received data
GOTO Rcv_RS232
MOVF RCREG, W
RETURN
;End of serial routines
; Activating RA0 pin17 on PIC16F628
LED Equ 0 ;set constant LED = 0
LEDPORT Equ PORTA ;set constant LEDPORT = 'PORTA'
org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running
movlw 0x07
movwf CMCON ;turn comparators off
bsf STATUS, RP0 ;select bank 1
movlw b'00000010' ;set PortB all outputs except RB1
movwf TRISB
movwf TRISA ;set PortA all outputs
bcf STATUS, RP0 ;select bank 0
clrf PORTA
clrf PORTB ;set all outputs 0
Loop
bsf LEDPORT, LED ;turn on RA0 only!
call Delay ;this waits for a while!
goto Loop ;go back and do it again
Delay movlw d'250' ;delay 250 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7 ;delay 1mS
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
; PWM implementation via strobe and pin9 of PIC16F628
portb equ 0x06 ; port b equate
duty equ 0x0c ; length of duty cycle
temp equ 0x0d ; length of duty cycle
;---------------------------------------------------------------------
c equ 0 ; status bit to check after subtraction
;---------------------------------------------------------------------
org 0x000
movlw 0x00 ; load W with 0x00 make port B output
tris portb ; copy W tristate to port B outputs
movlw 0x00 ; fill w with zeroes
movwf portb ; set port b outputs to low
rstrt movlw d'0'
movwf portb
movlw d'110' ; Duty cycle length
movwf duty
b0loop movf duty,w
movwf temp
bsf portb,0
pwma nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
decfsz temp
goto pwma
movlw d'255'
movwf temp
movf duty,w
subwf temp,f
bcf portb,0
pwmb nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
decfsz temp
goto pwmb
goto rstrt
;----------------------------------------------------------------------
end