Here is a ASM program I have written. I'm basically looking for tips and help with structure or anything. I havent been able to test this yet as I dont have a PIC/Programmer. I have simulate it with MPLAB IDE and everything looks fine other than when I loop to wait for TXIF to get set (The serial transmission was complete) the simulate loops forever.. But i suspect this to be a problem with something else. (Simulation or something?)
I would mainly like any tips with anything you see or if you have a better way of doing it.. Dont hesitate to say "Thats a stupid way to do..."
I would mainly like any tips with anything you see or if you have a better way of doing it.. Dont hesitate to say "Thats a stupid way to do..."
Code:
;Testing and Simulation
LIST P=PIC16F877 ;tell assembler what chip we are using
include "P16F877.inc" ;include the defaults for the chip
__config 0x3D18 ;sets the configuration settings
;(oscillator type etc.)
;Yay for Variables!
TEMPW EQU H'20' ;This is the start of the General Registers.
Motor0 EQU H'21' ; Motor0 speed
Motor1 EQU H'22' ; Motor0 speed
org 0x0000 ;org sets the origin, 0x0000
goto main ;this is where the program starts running
org 0x0004 ;org sets the origin, 0x0004
goto IntH ;this is where interrupts are vectored
main
movlw 0x07
movwf CCP1CON ;turn off CCP
;select bank 1
bsf STATUS, RP0 ;set RP0
bcf STATUS, RP1 ;clear RP1
;set PortX(all ports) all outputs
movlw b'00000000'
movwf TRISE
movwf TRISD
movwf TRISC
movwf TRISB
movwf TRISA
bsf TRISB, 0 ; Using RB0/INT as interrupt here.
;Lets Timer0 this baby. Yeah uh I dont have a internal clock..
; I'll fix this someday.
bcf OPTION_REG, T0CS ; Use interal CS for T0
bsf OPTION_REG, INTEDG ; Interrupt Edge trigger.
;Lets play with INTCON (Interrupts) Either banks
; movlw b'10010000' ;Enable Interrupts. Timer0 overflow.
; movwf INTCON ;Maybe better to do bitwise ops?
bsf INTCON, GIE
bsf INTCON, INTE
bcf INTCON, INTF
; Serial stuff
movlw d'30'
movwf SPBRG ; Set the baud rate.
;TXSTA
bcf TXSTA, TX9 ;8bit transmission
bsf TXSTA, TXEN ;Transmit Enable bit
bcf TXSTA, SYNC ;Asynchro mode idk?
bcf TXSTA, BRGH ;low speed baud rate
;select bank 0
bcf STATUS, RP0 ;clear RP0
bcf STATUS, RP1 ;clear RP1
;RCSTA - Its in bank 0
bsf RCSTA, SPEN ;Serial Port Enable. Do I need this? sure..
bcf RCSTA, RX9 ;8bit receive
bcf RCSTA, CREN ;Continous Receive disable
;Move forward... forever..
call Forward
Loop
movlw 0xff
movwf PORTA ;set all bits on
movwf PORTC
movlw 0x00
movwf PORTA
movwf PORTC ;set all bits off
goto Loop ;go back and do it again
Forward
movlw b'111111'
movwf Motor0
movwf Motor1
call gomotor0
call gomotor1
return
gomotor0
call SerStart
call SerChk
movlw b'0000001'
movwf TXREG
call SerChk
movfw Motor0
movwf TXREG
return
gomotor1
call SerStart
call SerChk
movlw b'0000001'
movwf TXREG
call SerChk
movfw Motor0
movwf TXREG
return
SerStart
movlw 0x80
movwf TXREG
call SerChk
movlw 0x00
movwf TXREG
return
SerChk
btfss PIR1, TXIF ;Test if the data has been sent to buffer
goto $-1 ; Does this work?
return
;----Our Interrupt Handler will go here.----;
IntH
movwf TEMPW
nop
nop
nop
nop
bcf INTCON, INTF ;Lets set thing back..
movfw TEMPW ;Restore w
RETFIE
end