btfss fsr,4
goto Byte_plus ;a sequence that increments FSR and loads next data byte
btfss fsr,2
goto Byte_plus
btfss fsr,1
goto Byte_plus
call delays ; sets a flash rate
goto set_FSR ;starts data loading again
bcf status,z
movlw b'10110'
xorwf fsr,w
btfss status,z ;looking for zero
goto Byte_plus
call delays
goto set_FSR
Ser_Loop
rrf W_Byte,f
btfss status,c
bcf B_Out
** btfsc status,c
bsf B_Out
; call dly_417
decfsz B_count,f
** goto Ser_Loop
bsf B_out ;Stop bit
; call dly_417 ;stop bit
movlw 'H' ;
call PutSer ;
movlw 'a' ;
call PutSer ;
movlw 'p' ;
call PutSer ;
movlw 'p' ;
call PutSer ;
movlw 'y' ;
call PutSer ;
movlw ' ' ;
call PutSer ;
More to your point, I did not know I could just call constant ascii characters like that. I will have to try it. Where is it described?
lookup_table
mov index_reg, w
addwf PCL, f
retlw 0x48 ;H
retlw 0x41 ;A
retlw 0x50 ;P
retlw 0x50 ;P
retlw 0x59 ;Y
;******************************************************************
; *
; Filename: 12F509 Serial.asm *
; Author: Mike McLaren, K8LH *
; Date: 04-Jan-12 *
; *
; bit banged serial example *
; *
; MPLab: 8.80 (tabs=8) *
; MPAsm: 5.43 *
; *
;******************************************************************
include "p12f509.inc"
errorlevel -302, -224
list st=off
__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _XT_OSC
radix dec
;--< variables >---------------------------------------------------
delaylo equ 0x07 ;
delayhi equ 0x08 ;
txbyte equ 0x09 ;
bitctr equ 0x0A ;
;--< defines >-----------------------------------------------------
CTS equ 0 ; GP0 = serial CTS
TXD equ 1 ; GP1 = serial TXD
;******************************************************************
; DelayCy() subsystem macro generates five instructions *
;******************************************************************
clock equ 4 ; 4, 8, 12, 16, or 20 MHz clock
usecs equ clock/4 ; cycles/microsecond multiplier
msecs equ clock/4*1000 ; cycles/millisecond multiplier
DelayCy macro delay ; 12..327690 cycle range
movlw high((delay-12)/5)+1
movwf delayhi
movlw low ((delay-12)/5)+1
movwf delaylo
call uDelay-((delay-12)%5)
endm
;******************************************************************
; *
;******************************************************************
org 0x000
Init
movwf OSCCAL ; factory calibration value |B0
movlw b'001001' ; |B0
tris GPIO ; GP0 & GP3 inputs |B0
movlw b'10000000' ; |B0
option ; enable weak pull-ups |B0
;
DelayCy(100*msecs) ; delay 100 msecs |B0
;
; turn on LCD and print string
;
movlw 0x18 ; |B0
call Put232 ; turn on display |B0
DelayCy(5*msecs) ; delay 5 msecs |B0
movlw 'H' ; |B0
call Put232 ; |B0
movlw 'e' ; |B0
call Put232 ; |B0
movlw 'l' ; |B0
call Put232 ; |B0
movlw 'l' ; |B0
call Put232 ; |B0
movlw 'o' ; |B0
call Put232 ; |B0
goto $ ; loop forever |B0
;******************************************************************
; Put232 (9600 baud) *
;******************************************************************
Put232
movwf txbyte ; save Tx data byte |B0
movlw 10 ; 1 start + 8 data + 1 stop bit |B0
movwf bitctr ; setup bit counter |B0
clrc ; C = 0 (start bit) |B0
goto SendBit ; send start bit |B0
NextBit
DelayCy(104*usecs-10) ; 104 usecs minus 10 cycles |B0
setc ; always shift in a 'stop' bit |B0
rrf txbyte,F ; put data bit in Carry |B0
SendBit
movf GPIO,W ; read port |B0
iorlw 1<<TXD ; set TXD pin bit to 1 |B0
skpc ; if data bit = 1 skip, else |B0
xorlw 1<<TXD ; set TXD pin bit to 0 |B0
movwf GPIO ; precise update intervals |B0
decfsz bitctr,F ; done? yes, skip, else |B0
goto NextBit ; send next bit |B0
retlw 0 ;
;******************************************************************
; DelayCy() subsystem "uDelay" subroutine *
;******************************************************************
nop ; entry for (delay-12)%5 == 4 |B0
nop ; entry for (delay-12)%5 == 3 |B0
nop ; entry for (delay-12)%5 == 2 |B0
nop ; entry for (delay-12)%5 == 1 |B0
uDelay decf delaylo,F ; 5 cycle loop |B0
skpnz ; |B0
decfsz delayhi,F ; |B0
goto uDelay ; |B0
retlw 0 ; |B0
;******************************************************************
end
@Mike,
The program almost worked from the start. I needed to read up on the pseudo-instructions (black ops?) to begin to figure it out. On the oscilloscope, the start bit was showing as a very short blip, so I added another delay right after the "clrc" instruction to get the result shown.
Init
movwf OSCCAL ; factory calibration value |B0
movlw 1<<TXD ; |B0
movwf GPIO ; set TXD output to '1' (stop) |B0
movlw b'001001' ; |B0
tris GPIO ; GP0 & GP3 inputs |B0
movlw b'10000000' ; |B0
option ; enable GP0 & GP3 weak pull-ups |B0
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?