CAD CAM EDM DRO - Yahoo Group Archive

Some PIC code...

Posted by Matt Shaver
on 2000-11-09 21:21:11 UTC
beer@... wrote:
>
> On 9 Nov, CAD_CAM_EDM_DRO@egroups.com wrote:
>
> > Are you willing to share some code for the PIC ...
> > Hate to reinvent the wheel. I think Ballendo is interested
> > also.
>
> Look for a
> keypress and bitbang a serial byte. Screw all handshaking .. none
> required at these speeds.
>
> And yes, if I can find the code, I'll certainly post it. I'll try to
> check over the weekend.

I thought folks were looking for PIC code that implements a half-duplex
UART some time in the past, and I never got around to posting my
version. Here is a little (unfinished) app that has that code in it:

;
; Title: BE Master Control
; Version: 0.1
; By: Matt Shaver
; Copyright: 1998 (the project's dead, GPL...)
;
;Internal Symbols
;
;PIC16C54 = 00000000b
;PIC16C55 = 00000001b
;PIC16C56 = 00000010b
;PIC16C57 = 00000011b
;
;LP_OSC = 11000000b
;XT_OSC = 11000001b
;HS_OSC = 11000010b
;RC_OSC = 11000011b
;WDT_OFF = 10110000b
;WDT_ON = 10110100b
;PROTECT_ON = 01110000b
;PROTECT_OFF = 01111000b
;
;INDIRECT = 0
;RTCC = 1
;PC = 2
;STATUS = 3
;FSR = 4
;RA = 5
;RB = 6
;RC = 7
;
;C = STATUS.0
;DC = STATUS.1
;Z = STATUS.2
;PD = STATUS.3
;TO = STATUS.4
;PA0 = STATUS.5
;PA1 = STATUS.6
;PA2 = STATUS.7
;
;Variable Declarations
;
;Bit 4 of option reg must = 1 or rtcc will inc itself on wdt reset
option_byte = 00h
trisa_byte = 0ffh
trisb_byte = 0ffh

transmit_reg = 08h
recieve_reg = 09h
bit_count = 0ah
delay_count = 0bh
mirror_reg = 0ch
flag_reg = 0eh

transmit_bit = ra.0
recieve_bit = ra.1
ra2_bit = ra.2
ra3_bit = ra.3

org 0
device pic16c54,hs_osc,wdt_off,protect_off
id checksum
reset main

;****************************************************************************
; Procedure Name : send_character
; Function : Sends the character and returns
;****************************************************************************
send_character
movwf transmit_reg
movlw 09h
movwf bit_count
start_bit
bcf c ;1 cycle
next_bit
btfsc c ;1 cycle (2 if skip)
movlw 0ffh ;1 cycle
btfss c ;2 cycles (1 if no skip)
movlw 0feh ;1 cycle

tris ra ;1 cycle (movwf ra for active high)

movlw 65 ;1 cycle (64-66 is OK)
movwf delay_count ;1 cycle
tx_bit_delay
decfsz delay_count,1 ;1 cycle (2 if skip)
goto tx_bit_delay ;2 cycles

rrf transmit_reg,1 ;1 cycle
decfsz bit_count,1 ;1 cycle (2 if skip)
goto next_bit ;2 cycles
stop_bit
movlw 0ffh

tris ra ;1 cycle (movwf ra for active high)

movlw 69 ;1 cycle (19,67,69)
movwf delay_count ;1 cycle
tx_stopbit_delay
decfsz delay_count,1 ;1 cycle (2 if skip)
goto tx_stopbit_delay ;2 cycles

retlw 0h
;****************************************************************************
; Procedure Name : recieve_character
; Function : Recieves a character and places it in recieve_reg
;****************************************************************************

recieve_character
movlw 08h
movwf bit_count
rx_start_bit
call service_io ;
btfsc recieve_bit ;1 cycle
goto rx_start_bit ;2 cycles
movlw 98 ;1 cycle (83)
movwf delay_count ;1 cycle
rx_next_bit
decfsz delay_count,1 ;1 cycle (2 if skip)
goto rx_next_bit ;2 cycles

btfsc recieve_bit ;1 cycle (2 if skip)
bsf c ;1 cycle
btfss recieve_bit ;2 cycles (1 if no skip)
bcf c ;1 cycle
rrf recieve_reg,1 ;1 cycle
movlw 65 ;1 cycle (66)
movwf delay_count ;1 cycle
decfsz bit_count,1 ;1 cycle (2 if skip)
goto rx_next_bit ;2 cycles
rx_stop_bit
movlw 69 ;1 cycle (69)
movwf delay_count ;1 cycle
rx_stopbit_delay
decfsz delay_count,1 ;1 cycle (2 if skip)
goto rx_stopbit_delay ;2 cycles
retlw 0h

;****************************************************************************
; Procedure Name : service_io
; Function : Sets output bits to control relays
;****************************************************************************
service_io
movlw trisb_byte
tris rb
movlw 0h
movwf rb

retlw 0
;****************************************************************************
; Procedure Name : main
; Function : Main Routine
;****************************************************************************

main
;Initialize WDT and I/O

movlw option_byte
option
movlw trisa_byte
tris ra
movlw 00h ;This ensures that when a bit is enabled
movwf ra ;as an output it goes low!

bcf flag_reg,0 ;First time through

movlw 00h
movwf mirror_reg

loop

movlw '$'
btfsc flag_reg,0
movlw '>'
; movwf transmit_reg
call send_character

bsf flag_reg,0 ;Been here before

parse_commands
call recieve_character

parse_cr
movlw 0ah
xorwf recieve_reg,0
btfsc z
goto command_complete

parse_lf
movlw 0dh
xorwf recieve_reg,0
btfss z
goto parse_bit_0_on

command_complete
movlw 14h
; movwf transmit_reg
call send_character

check_bit_0
btfss mirror_reg,0
goto check_bit_1

movlw 18h
; movwf transmit_reg
call send_character

check_bit_1
btfss mirror_reg,1
goto check_bit_2

movlw 19h
; movwf transmit_reg
call send_character

check_bit_2
btfss mirror_reg,2
goto check_bit_3

movlw 1ah
; movwf transmit_reg
call send_character

check_bit_3
btfss mirror_reg,3
goto check_bit_4

movlw 1bh
; movwf transmit_reg
call send_character

check_bit_4
btfss mirror_reg,4
goto check_bit_5

movlw 1ch
; movwf transmit_reg
call send_character

check_bit_5
btfss mirror_reg,5
goto check_bit_6

movlw 1dh
; movwf transmit_reg
call send_character

check_bit_6
btfss mirror_reg,6
goto check_bit_7

movlw 1eh
; movwf transmit_reg
call send_character

check_bit_7
btfss mirror_reg,7
goto check_done

movlw 1fh
; movwf transmit_reg
call send_character

check_done
movlw 03h
; movwf transmit_reg
call send_character

movlw 0dh
; movwf transmit_reg
call send_character

movlw 0ah
; movwf transmit_reg
call send_character

goto loop

parse_bit_0_on
movlw 'A'
xorwf recieve_reg,0
btfss z
goto parse_bit_0_off

bsf mirror_reg,0
goto parse_done

parse_bit_0_off
movlw 'a'
xorwf recieve_reg,0
btfss z
goto parse_bit_1_on

bcf mirror_reg,0
goto parse_done

parse_bit_1_on
movlw 'B'
xorwf recieve_reg,0
btfss z
goto parse_bit_1_off

bsf mirror_reg,1
goto parse_done

parse_bit_1_off
movlw 'b'
xorwf recieve_reg,0
btfss z
goto parse_bit_2_on

bcf mirror_reg,1
goto parse_done

parse_bit_2_on
movlw 'C'
xorwf recieve_reg,0
btfss z
goto parse_bit_2_off

bsf mirror_reg,2
goto parse_done

parse_bit_2_off
movlw 'c'
xorwf recieve_reg,0
btfss z
goto parse_bit_3_on

bcf mirror_reg,2
goto parse_done

parse_bit_3_on
movlw 'D'
xorwf recieve_reg,0
btfss z
goto parse_bit_3_off

bsf mirror_reg,3
goto parse_done

parse_bit_3_off
movlw 'd'
xorwf recieve_reg,0
btfss z
goto parse_bit_4_on

bcf mirror_reg,3
goto parse_done

parse_bit_4_on
movlw 'E'
xorwf recieve_reg,0
btfss z
goto parse_bit_4_off

bsf mirror_reg,4
goto parse_done

parse_bit_4_off
movlw 'e'
xorwf recieve_reg,0
btfss z
goto parse_bit_5_on

bcf mirror_reg,4
goto parse_done

parse_bit_5_on
movlw 'F'
xorwf recieve_reg,0
btfss z
goto parse_bit_5_off


bsf mirror_reg,5
goto parse_done

parse_bit_5_off
movlw 'f'
xorwf recieve_reg,0
btfss z
goto parse_bit_6_on

bcf mirror_reg,5
goto parse_done

parse_bit_6_on
movlw 'G'
xorwf recieve_reg,0
btfss z
goto parse_bit_6_off

bsf mirror_reg,6
goto parse_done

parse_bit_6_off
movlw 'g'
xorwf recieve_reg,0
btfss z
goto parse_bit_7_on

bcf mirror_reg,6
goto parse_done

parse_bit_7_on
movlw 'H'
xorwf recieve_reg,0
btfss z
goto parse_bit_7_off

bsf mirror_reg,7
goto parse_done

parse_bit_7_off
movlw 'h'
xorwf recieve_reg,0
btfss z
goto parse_commands

bcf mirror_reg,7

parse_done
movf recieve_reg,0
; movwf transmit_reg
call send_character

goto parse_commands

This was part of a system that controlled a washing machine and it had
four PICs in it that each controlled a separate portion of the machine
(1-Relays, 2-Keyboard Scanning, 3-Indicator Lamps (a clone of the Relay
module), and 4-The Master Controller that monitored the inputs
(switches, water temp sensor, etc.). The PICs communicated via a
multidrop serial bus of my own creation. I started by hooking each of
the boards to a PC serial port, and debugging each one separately, then
got them all to cooperate together. It also had a Scott Edwards
Electronics LCD display (also PIC controlled!) on the same serial bus,
but all the inter-processor messages were formed by character codes that
the display ignored (pretty clever huh...). I even had a menu system
going on the LCD that allowed setting the clock, starting a wash cycle,
etc. (I think this must be an earlier version because that's not in
here). A lot of the details are pretty fuzzy at this point, but if this
is really valuable to someone, I can dig up PIC code that does all kinds
of things. I had it working pretty good, but the customer couldn't wait
another couple months for it to be finished, so they hired a new
contractor who scrapped all I had done and then took another year or so
to deliver a working system that only cost about 5 times as much (it's
still in debug today...).

Matt

P.S. I've been real busy lately, great stuff on the list, lots of half
finished replies in my "Drafts" folder.

Discussion Thread

Matt Shaver 2000-11-09 21:21:11 UTC Some PIC code... Alan Marconett KM6VV 2000-11-10 10:25:10 UTC Re: [CAD_CAM_EDM_DRO] Some PIC code...