Convert Pic code to run on PSoC 5

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
IaCa_4674211
Level 3
Level 3
25 replies posted 10 replies posted 10 questions asked

Hello, Can anyone help me convert this ancient 8bit pic code to run on the PSoC 5?, Ideally I would like to use flash instead of EEprom, I do not know enough about the Pic code structure, 

start-up the very first time, RA4 (port A.4) is held high and
; thereby initializing the rec, pulse, wait time in the EE plume.
; If RA4 is low during takeoff, the EE plume is read instead.
; Note that RA4 has dual function as it at high (after
; start can be used (via RA0, RA1) to adjust the number of pulses
; REMEMBER to set low again before the next ON / OFF.
;
;
;
; LIST P = 16C84, F = INHX8M


include "p16c84.inc";
; uP PIC16C84 include module ver. 1.00

; ----------------- DIV -----------------

ORG 0; Dummy origin
goto INIT; ; jump to INIT
; -------------- ------------- constants

d1 equ. 20; pulse time in us
d2 equ. 10; (wait before rec.) wait for response in us
d3 equ .5; receive in ms
d4 equ .40; (ms wait before next) wait ms before the next pulse
delay equ .6; ; delay to 1 ms hours
loop equ 0Ch; RAM 0C
xus equ 10h; RAM 10
xms equ 11h; RAM 11
pulse_time equ 15h; RAM 15
w_b_r equ 16h; RAM 16
rec_time equ 17h; RAM 17
w_b_n equ 18h; RAM 18


; RAM 11; is used by x ms hours
; RAM 12.13; used by us hours
; RAM 14; 8 flags, F0..F7
; RAM 15; pulse_time
; RAM 16; w_b_r
; RAM 17; rec_time
; RAM 18; w_b_n
;
; EEADR 00; set to 0 at startup
; ---------------- TIMER ------------------
wait_1us; ; ca 1us wait
nop;
return

wait_xus; wait x microsec.
J4
call wait_1us
decfsz xus, 1; T'l xus-1
goto J4
return

wait_1ms; ; 1 ms hours
movlw .5; number of passes for 1 ms
movwf 13; move w to RAM 13
J2 movlw delay; ; w = delay (correction)
movwf 12; move w to RAM 12
J1 decfsz 12.1; Tl RAM12-1 or later
goto J1; repeat
decfsz 13; T'l RAM13-1 or end
goto J2; repeat
return

wait_xms; Wait x milliseconds
J3 call wait_1ms
decfsz xms, 1; T xl-1
goto J3
return

; ----------- EEPROM MODULE FOR PIC16C84
; Rev 1.00
; 27th / 07-95
; note: use timer

wadr equ 2Fh; address in RAM 2F
value equ 2Eh; Data in RAM 2E

WR_EEPROM; write EEPROM (data in RAM 2E + adr in RAM 2E)
movf wadr, W; w = ADR
movwf EEADR; EEADR = w
movf value, W; w = data
movwf EEDATA; EEDATA = w
; --- write sequnce
bsf STATUS, RP0; EEPROM write enable
bcf INTCON, GIE; disable interupts
movlw 0x55; W = 55H
movwf EECON2; EECON2 = w
movlw 0xAA; w = Oh
movwf EECON2; EECON2 = w
bsf EECON1, WR; EECON1 = write
movlw .100; load time writing
movwf xms; move w to xms
call wait_xms; wait in ms
; --- end
; return

RD_EEPROM; should be in RAM 2F
movf wadr, W; data is delivered in RAM 2E
movwf EEADR; EEADR = w (adr)
bsf STATUS, RP0; bank 1
bsf EECON1, RD; set RD bit (self extinguishes)
bcf STATUS, RP0; bank 0
movf EEDATA, W; w = data
movwf value; data = w
; --- end
return
; -------------- END EEPROM MODULE


; ------------ DATA CHANGES -----------
Update
btfsc 5.4; first check bit 4
goto heart rate, adjust number of pulses
btfsc 5.0; If bit 0 is set
incf rec_time, 1; "step up" rec. hour + 1
btfsc 5.1; If bit 1 is set
decfsz rec_time, 1; "step down" rec. hour - 1
btfsc 5.2; If bit 2 is set
incf w_b_r, 1; "step up" wait before rec + 1
btfsc 5.3; If bit 3 is set
decfsz w_b_r, 1; "step down" wait before - 1
goto end, otherwise end

if 5.4
pulse just
btfsc 5.0; If bits 0 and 4 are set
incf pulse_time, 1; "step up" pulse + 1
btfsc 5.1; If bits 1 and 4 are set
decfsz pulse_time, 1; "step down" pulse - 1
GOTO end, jump to end

end
set up address + data for EEPROM change
save number of pulses
movf pulse_time, W; move to W
movwf value; value = rec_time
movwf wadr; set address
movlw 01h; to 01 hex in EE
CALL WR_EEPROM; write in EE
save wait time before receiving
movf w_b_r, W; move to W
movwf value; value = rec_time
movwf wadr; set address
movlw 02h; to 02 hex in EE
CALL WR_EEPROM; write in EE
save recipient time
movf rec_time, W; move to W
movwf value; value = rec_time
movwf wadr; set address
movlw 03h; to 03 hex in EE
CALL WR_EEPROM; write in EE

; hours start
movlw 04h
movwf loop; put 2 in RAM 0C
T_1
wait 1 sec
movlw .255; ; 1/4 sec load
movwf xms; move w to xms
call wait_xms; wait for w_b_n ms
decfsz walk, 1; walk
goto T_1
;than
return
DEFAULT
movlw d1; w = delay 1
movwf puls_time; Pulse time = w
movwf d2; w = delay 2
movwf w_b_r; wait before receive
movwf value; data (EE) = w
movlw d3; w = delay 3
movwf rec_time; record time
movwf value; data (EE) = w
movlw d4; w = delay 4
movwf w_b_n; wait (deleted later)
CALL Update; write to EE
goto MAIN


; -------------- INIT -------------------
INIT
output init
movlw B'11111111 '; set w = 0D
movwf PORTB; move w to port B
movlw B'00000000 '; set w = 00
tris PORTB; look out all I / O direction
input init
movlw B'11111 '; set bit 0..4 for input
tris PORTA; set port A
; init RAM / EEPROM
btfsc PORTA, 4; If port A bit 0 read by default
goto DEFAULT
movlw 01h; ; W = 01h
movwf wadr; adr = w
call RD_EEPROM; Read EE
movf value, W; w = EEPROM data
movwf pulse_time; pulse = w
movlw 02h; ; W = 02h
movwf wadr; adr = w
call RD_EEPROM; Read EE
movf value, W; w = EEPROM data
movwf w_b_r; wait before receive
movlw 03h; ; W = 03h
movwf wadr; adr = w
call RD_EEPROM; Read EE
movf value, W; w = EEPROM data
movwf rec_time; record time
movlw d4; w = d4 (deleted later)
movwf w_b_n; wait (deleted later)
goto MAIN; HOP TO THE HEADLY
;---------------- PULSE -------------------
pulse
bcf PORTB, 0; bit 3 = 0 (output)
movf pulse_time, 0; move pulse_time to w
movwf xus; move time to RAM11
call wait_xus; wait for x us
bsf PORTB, 0
return

;--------------- RECEIVE ------------------
receiver
bcf PORTB, 3; bit 0 = 0 (receiver opens)
movf rec_time, 0; move time in us to w
movwf xus; move time in RAM16
call wait_xus; wait for x us
bsf PORTB, 3; close receiver
return


; ----------------- MAIN --------------
MAIN
; Pulse
call pulse; call pulse routine
; Wait
movf w_b_r, W; load w with wait
movwf xus; move w to xus
call wait_xus; wait in w_b_r us
; receive
call receiver; open receiver
; Wait
movf w_b_n, W; load time to next pulse
movwf xms; move w to xms
call wait_xms; wait for w_b_n ms
; read input
btfsc 5.0; if up active
call update; call update
btfsc 5.1; if down active
call update; call update
btfsc 5.2; if up active
call update; call update
btfsc 5.3; if down active
call update; call update
; repeat
goto MAIN
than
; END

0 Likes
1 Solution

Unfortunately, I am not able to do this,

 

Thanks for your help

 

Cheers

View solution in original post

0 Likes
4 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

IaCa,

I recommend describing what you want to achieve instead. Will be simpler, than decoding unknown assembler code.

 

0 Likes
IaCa_4674211
Level 3
Level 3
25 replies posted 10 replies posted 10 questions asked

Hi, What I am wanting to achieve, is to create an adjustable pulse timing controller, capable of waiting before receiving (10uSec.),receiving pulses(0 .5mSec.) from a bilateral switch, and wait/hold(0.40msec.)before the next pulse, and delay (0.6msec.) and output to a quad CMOS Nand gate,  there is a lot of critical information withing the assembler code I do not understand ,

Kind Regards 

0 Likes
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

IaCa,

It would be nice if you can draw a timing diagram for clarity. The specs seem to be manageable.

 

0 Likes

Unfortunately, I am not able to do this,

 

Thanks for your help

 

Cheers

0 Likes