CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Can assembly code for an old PIC1650 be adapted for CCS C?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
djsb



Joined: 29 Jan 2011
Posts: 41

View user's profile Send private message

Can assembly code for an old PIC1650 be adapted for CCS C?
PostPosted: Fri Dec 16, 2022 8:57 am     Reply with quote

I have an assembly listing for an old PIC1650 MCU. The code is contained in "PIC SERIES MICROCOMPUTER DATA MANUAL"
http://www.bitsavers.org/components/gi/PIC/1983_PIC_Series_Microcomputer_Data_Manual.pdf pages 212 to 220 entitled "Interfacing a PIC Microcomputer with the ER1400 EAROM". The assembly code starts on page 216 and ends on page 220. A lot of the assembler mnemonics appear similar to modern chips, but I'm assuming that the assembler is no longer available.
However, I would like to adapt this code (which I have yet to extract from the app note) for use in CCS and implement it on a modern pic. My aim is to understand how the ER1400 EAROM on my Revox B261 FM tuner works and hopefully make some improvements eventually. It's also a learning experience for me and a bit of a challenge. I have also posted here on EEVBLOG

https://www.eevblog.com/forum/microcontrollers/how-does-this-old-er1400-earom-work/msg4584700/#msg4584700

I've also got a spare ER1400 EAROM and i'm going to make a prototype on breadboard/stripboard to test out the code. How would I go about transfering the code from assembly to CCS C code? Any tips and practical info (apart from don't bother). Thanks.

PS. If I extract the code I will put it on my EEVBLOG post above as an attachment and let everyone know. Thanks.
PrinceNai



Joined: 31 Oct 2016
Posts: 480
Location: Montenegro

View user's profile Send private message

PostPosted: Fri Dec 16, 2022 9:22 am     Reply with quote

Probably WAY easier to study ER1400 datasheet and write your own code. This question is very similar to a currently running topic. How to get CCS C code from .asm or .hex. No easy way, maybe no way at all without the exact knowledge of what the original author had in mind at the time it was coded. The code, as written, wasn't done with any kind of C functions in mind.
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Fri Dec 16, 2022 9:29 am     Reply with quote

The assembly listing appears to be well commented so it will be a little work but not bad.
Study the comments and matching assembler instructions and write a similar instruction in C.
PrinceNai



Joined: 31 Oct 2016
Posts: 480
Location: Montenegro

View user's profile Send private message

PostPosted: Fri Dec 16, 2022 9:37 am     Reply with quote

But as Gaugeguy said, it is a well documented code. I'd study it to see what needs to be done to interface with that chip. Read the datasheet. Which pin or pins need to go to a certain level. Timings. Payload. Then write my own. Easier than blindly following someone's steps.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Dec 16, 2022 9:47 am     Reply with quote

this...
How to get CCS C code from .asm or .hex.

presupposes the programmer did use C as his source language.
I did a LOT of PIC Assembler until I bought PCM v2.534 !


One possible 'cheat' is to use the asm code as 'inline' ,once modifications have been done to 'port' over to a modern PIC.
Had a very quick look at the code(212-220...) and it should be easy to cut equivalent C code
Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Fri Dec 16, 2022 10:24 am     Reply with quote

Your big issue, will be interfacing the device.
Straining my memory, but the device was General Instruments, and used
a quite high -ve supply voltage (something over 30v). So there is a lot of
interfacing going to be involved to drive it off a 5v PIC. It had some control
bits that configured the mode, and data was sent by clocking it in (two
wire interface). The same data pin was used bidirectionally when reading.
You could use the SPI lines from a PIC, with the right interface logic.
The clock rate was low though (about 15KHz rings a bell).
Data was clocked on the falling edge when writing to the chip and the
rising edge when reading.
The design life for the chip was about 10years, but fell with how often a
cell was used (just like EEPROM), and the actual life cycles were quite low.
If it's been used a lot, the chip may well be dead now.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Fri Dec 16, 2022 6:15 pm     Reply with quote

Overall a large part of the document is explanations of various operations
which are now handled easily by a line or two of C.
I saw at least two places where multiple pages of code/etc could be replaced
by two or three lines of C code. In other places routines for keypads and
LCD/LED displays are available in the Code library. The routine for EAROM is
completely outdated and can be handled with a couple of lines of code dealing
with internal PIC ROM or EPROM storage. All in all, in my opinion, the effort to
convert the assembler is a big waste of time when it can be done a much
simpler/better way in CCS C.
_________________
Google and Forum Search are some of your best tools!!!!
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Dec 16, 2022 9:34 pm     Reply with quote

wow...
https://abra-electronics.com/ics-semiconductors/eeproms/er1400-eeprom-1400bit-100x14-14-pin-dip-en.html

you can still buy them !!!!
OK, curiosity got to me...

datasheet says -35volts..hmmmm...
Actually this could be a fun project, even for a dinosaur like me !!!

I'd probably start by copy/cut/paste the asm listed on pgs 210-220+-, into ONE long page, so i could easily SEE what's going on, get a 'feel' as to how their minds were thinking back then...

1st step is to get the timing correct ! There's an 18ms loop, so you could 'play computer', count cycles and work backwards to see what their PIC's clock was (my guess... 1MHz, that was kind of a standard back then....)

Decide on a PIC, interface as shown, cut some test code, see what happens.
I'd be tempted to use inline ASM, then maybe convert to C. ONLY when you're 100% happy that it works, THEN remove your REVOX chip and see if you can read it.
Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Sat Dec 17, 2022 5:37 am     Reply with quote

Went and reminded myself about the device.
The driving is the hard part. You need to be able to drive the C lines to
select what you want to do as well as the clock and data lines. On the data
line, the driver you have needs to be able to turn off when you want to
read the device. For all the other lines, it struck me that the isolated
drivers for MOSFET gates would do the job brilliantly, and simplify the
circuit a lot. There are ones rated for 35v from several suppliers, and
since they are isolated they would handle all the level shifting involved.
Just a thought. Smile
djsb



Joined: 29 Jan 2011
Posts: 41

View user's profile Send private message

PostPosted: Sat Dec 17, 2022 6:20 am     Reply with quote

Thanks everyone,
I'm currently OCRing
(I'm using NormCap https://dynobo.github.io/normcap/#features) the code listing from the General Instruments App note and saving it to a text file. That should take me the rest of the weekend. Then I'll go through the assembly listing and try to convert it to use a PIC16F819 as a first step. I'm a bit rusty on PIC assembly code, but this is an excuse to do a refresh. Crawl, walk, run as they say.






PS Regarding the circuitry, I'm going to stick with the same setup as used on the actual MCU PCB. Once I get that working, I can consider improvements if sensible.


Last edited by djsb on Sat Dec 17, 2022 6:34 am; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Dec 17, 2022 6:31 am     Reply with quote

found this...
https://www.eevblog.com/forum/testgear/tektronix-2445-2465-cal-settings-earom-er1400/
maybe the link to the programmer is still 'active' ??

kinda interesting that Tek used them ! must have been the 'new chip on the block' back then !!
djsb



Joined: 29 Jan 2011
Posts: 41

View user's profile Send private message

PostPosted: Sat Dec 17, 2022 6:39 am     Reply with quote

Thanks Temtronic,
Yes, the link is still active. It's another possibility if I can't get the original circuit topology working OK. I'm concentrating on the ASM listing first.

David.
Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Sun Dec 18, 2022 2:45 am     Reply with quote

I think when it launched, it was pretty much the only EE memory storing more
that a few tens of bytes. It was used in some Mullard kit as well, which is
where I met it. We had to modify an existing radio, and ended up using
one of these to hold the tuning parameters. If you look, the pull down
on the signals only has to go down to about half the supply voltage. We did
two basic voltage dividers feeding the bases of a pull up, and a separate pull
down transistor. By keeping these separate, on the 'read', we could just
leave both transistors off. The device was pretty easy to drive. I was using
a Z80 when doing this. It would have been about mid 1980's (know when
I had that job...). Most other memories then, were either UV EEPROM's, or
only OTP.
djsb



Joined: 29 Jan 2011
Posts: 41

View user's profile Send private message

PostPosted: Sun Dec 18, 2022 10:32 am     Reply with quote

Here is the assembly code listing from the GI app note

Code:

//*****************************************
//*****************************************
//** PROJECT: PIC1650--ER1400 INTERFACE  **
//** ADDRESS: GENERAL INSTRUMENT CORP.   **
//**          MICROELECTRONICS DIVISION  **
//**          600 WEST JOHN STREET       **
//**          HICKSVILLE, NY 11802       **
//** PHONE:  (516) 733-3000              **
//*****************************************
//*****************************************

//****************************************************
//****************************************************
//**  COPYRIGHT 1982 GENERAL INSTRUMENT CORPORATION **
//**  THIS FROGRAM IS PROTECTED AS AN UNPUBLISHED   **
//**  WORK UNDER THE COPYRIGHT ACT OF 1976 AND THE  **
//**  COMPUTER SOFTWARE ACT OF 1988.                **
//****************************************************
//****************************************************

//*************************
//*************************
//** I/O FILE ASSIGNMENT **
//*************************
//*************************

IOREG = 5 //ADDRESS OF FORT A

//*****************************************
//*****************************************
//** I/O BITS ASSIGNMENT FOR PORT A (F5) **
//** A +5 VOLT ON THE CONTROL BIT MEANS  **
//** LOGIC 0 FOR THE EAROM. 0 VOLT ON    **
//** THE CONTROL BIT MEANS LOGIC 1 FOR   **
//** THE ER1400 EAROM.                   **
//*****************************************             
//*****************************************


ERCLK  = 0  //14 KHZ CLOCK TO THE ER1400.
C1     = 1  //EAROM CONTROL BIT 1.
C2     = 2  //EAROM CONTROL BIT 2.
C3     = 3  //EAROM CONTROL BIT 3.
ERDATA = 4  //SERIAL DATA TO OR FROM EAROM.

//*******************************************
//*******************************************
//** FILE REGISTER ASSIGNMENTS.            **           
//** THIS EAROM INTERFACE ROUTINE UTILIZES **
//** F30 TO F37 IN THE PIC1650. IT IS      **
//** IMPORTANT THAT THESE EIGHT REGISTERS  **
//** ARE DEDICATED TO THIS ROUTINE ONLY.   **
//*******************************************
//*******************************************

FSR      =   4     //FILE SELECT REGISTER.
COUNT    =   30    //EAROM ROUTINE INTERNAL COUNTER.THIS COUNTER IS USED TO COUNT THE NUMBER OF EAROM CLOCKS.
CONAD3   =   31    //THE LSB OF THE 20-BIT EAROM.
CONAD2   =   32    //ADDRESS IN ONE-OUT-OF TEN
CONAD1   =   33    //CODE FORMAT.
TEMP     =   34    //TEMPORY REGISTER USED BY EAROM.
LOCATN   =   35    //ON ENTRY, THIS REGISTER CONTAINS THE BCD EAROM ADDRESS.THIS ROUTINE WILL CONVERT THIS BCD INTO THE FINAL ONE OF TEN CODE.
DATA1    =   36    //THIS IS THE LSB OF THE 14 BITS EAROM DATA.
DATA2    =   37    //THIS IS THE MSB OF THE 14 BITS EAROM DATA.


//*******************************************************
//*******************************************************
//** THIS IS THE READ EAROM ROUTINE. THE FOLLOWING     **
//** PARAMETER ARE NEEDED BEFORE CALLING THIS ROUTINE: **
//** PARAMETER: LOCATN (F35)-----THE BCD ADDRESS OF    **
//** THE EARROM LOCATION THAT HAS TO                   **
//** BE READ.                                          **
//** OUTPUT: DATA1 (F36)--- THE LSB OF THE 14          **
//**                        BITS EAROM DATA.           **
//**          DATA2 (F37)--- THE MSB OF THE 14          **
//**                        BITS EAROM DATA.           **
//*******************************************************
//*******************************************************

READ   RES  0             //READ EAROM ROUTINE ENTRY POINT.
       CALL ADEAR         //ADDRESS ER1400. COUNT LEFT AT ZERO.
      BSF COUNT,0        //SET COUNTER TO ONE.
      MOVLW B'11111101'  //CONTROL CODE FOR READ.
                         //DATA AND CLOCK HIGH.
      CALL ERTRAN        //READ THE DATA REGISTER, COUNT LEFT AT ZE (?).
      BSF COUNT,4        //SHIFT OUT 16 BITS (14 PLUS 2 TO
                          //NORMALIZE DATA TO LOWER
                          //6 BITS OF DATA2).
      MOVLW DATA1        //
      MOVWF FSR          //POINT TO DATA REGISTERS.
      MOVLW B'11100101'  //CON CODE FOR SHIFT DATA OUT.
      CALL ERTRAN        //SHIFT DATA OUT. LEAVE 77 IN W.
       ANDWF DATA2        //ENSURE BITS 6-7 CLEAR.
                         //
EXEAR  RES  0             //
       MOVLW B'11111111'  //CONTROL CODE FOR STANDBY.
                         //WITH CLOCK BIT SET.
      MOVWF IOREG        //OUTPUT CONTROL CODE
       RETLW 0
      
//**********************************************************************
//**********************************************************************
//**  THIS IS THE EAROM WRITE ROUTINE. THE FOLLOWING                  **
//**  PARAMETERS MUST BE SET UP BEFORE THIS ROUTINE                   **
//**  IS INVOKED.                                                     **
//**   PARAMETERS: LOCATN (F55)----THE BCD ADDRESS OF THE             **
//**                               EAROM LOCATION THAT NEW            **
//**                        DATA IS GOING TO BE STORED INTO    **
//**            DATA1 (F56) ----THE LOWER 8 BITS OF                **
//**                            NEW DATA.                          **
//**            DATA2 (F57) ----THE UPPER 6 BITS OF THE            **
//**                            NEW DATA PLUS TWO DON’T CARE BITS. **
//**   OUTPUT: NONE.                                                  **
//**********************************************************************
//**********************************************************************

WRITE RES 0               //EAROM WRITE ENTRY POINT.
      CALL ADEAR          //ADDRESS THE EAROM.
      MOVLW B'11111011'   //CON CODE FOR ERASE
                         //DATA & CLOCK HIGH ©
      MOVWF IOREG         //
     CALL W18MS          //DELAY 18MS. ON RETURN,
                          //14 IS STORED IN W.
      MOVWF COUNT         //SEND OUT 14 CLOCK PULSES.
     MOVLW DATA1         //STORE THE ADDRESS OF THE LOW
      MOVWF FSR           //BYTE OF NEW DATA INTO FSR.
                         //
     MOVLW B’11110001'   //CON CODE FOR ACCEPT DATA.
                          //DATA & CLOCK HIGH.
     CALL ERTRAN         //SHIFT THE DATA INTO THE EAROM
      MOVLW B'11111001'   //CON CODE FOR WRITE
      MOVWF IOREG         //DATA & CLOCK HIGH.
     CALL W18MS          //DELAY 18MS WITH CONTINOUS CLOCK.
     GOTO EXEAR          //EXIT FROM THIS EAROM INTERFACE
                          //ROUTINE AND RETURN TO MAIN PROGRAM.
                          //THE ER1400 IS PUT INTO STANDBY MODE.
                   

//***************************************************
//***************************************************
//**   THIS IS AN 18MS DELAY ROUTINE REQUIRED WHEN **
//**   WRITING DATA INTO THE ER1400 EAROM. DURING  **
//**   THIS 18MS PERIOD, A 14 KHZ EAROM CLOCK MUST **
//**   BE MAINTAINED. ON RETURN, THIS ROUTINE PUTS **
//**   A DECIMAL NUMBER 14 INTO THE W REGISTER.    **
//***************************************************
//***************************************************

WMID   RES 0
       XORWF IOREG        //TOGGLE THE EARROM CLOCK
       BIFSC COUNT,0
      RETLW .14          //RETURN TO CALLING ROUTINE.
       BSF   COUNT,0
W18MS  RES 0              //ENTRY POINT FOR 18 MS DELAY.
       CLRF  TEMP
W36US  RES 0
       DECFSZ TEMP
       GOTO WNZYET
      GOTO WMID
WNZYET RES 0
       MOVLW 1
       XORWF IOREG        //TOGGLE THE EAROM CLOCK.
      GOTO WPAD
WPAD   GOTO W36US

//*******************************************************
//*******************************************************
//** THIS ROUTINE TRANSFORMS THE BCD EAROM ADDRESS     **
//** STORED IN REGISTER 'LOCATN’ INTO THE 20-BIT       **
//** ONE-OUT-OF-TEN CODE REQUIRED BY THE ER1400 EAROM. **
//** THIS ONE-OF-TEN CODE IS STORED IN 'CONAD1’,       **
//** 'CONAD2’ AND 'CONAD3' WITH THE LSB IN *CONAD3'.   **
//** WHEN THIS 20-BIT ADDRESS IS FORMED, IT IS AUTO-   **
//** MATICALLY SENT TO THE EAROM BY EXECUTING THE      **
//** 'ERTRAN’ ROUTINE.                                 **
//*******************************************************
//*******************************************************

ADEAR   RES 0             //ENTRY POINT FOR ADDRESS TRANSFORM.
        MOVFW LOCATN      //PUT LOW NIBBLE OF ADDRESS
LOADDC  ANDLW 17          //IN LOW NIBBLE OF TEMP.
        MOVWF TEMP
        MOVLW .10         //NO OF LOOPS BEFORE.
       MOVWF COUNT       //THIS ADDRESS PART COMPLETE
        MOVLW 1           //DECREMENT FOR ADDRESS.
ROT3SR  SUBWF TEMP        //CLRS CARRY IF THIS PART OF ADDRESS.
                          //HAS NOW REACHED ZERO.
        RLF CONAD1        //SHIFT THE 'SHIFT REGISTER’
        RLF CONAD2
        RLF CONAD3
      DECFSZ COUNT      //SHIFTS DONE YET ?
        GOTO ROT3SR       //NOT YET
      BTFSS IOREG,2     //YES. WAS THIS SECOUND ADDRESS?
        GOTO OPADD        //YES. NOW OUTPUT CONVERTED ADDRESS.
      BCF IOREG,2       //NO. NOW CONVERT HIGH ADDRESS
      SWAPF LOCATN,0    //READY FOR HIGH NIBBLW(?) OF ADDRESS.
        GOTO LOADDC       //GO DO HIGH ADDRESS.
OPADD   MOVLW CONAD1      //PT FSR TO START OF CONVERTED ADDRESS
        MOVWF FSR         //3-REGISTER 'SHIFT REGISTER’
      MOVLW .20
        MOVWF COUNT       //SET FOR 10 BIT TRANSFER TO ERI400.
      MOVLW B’11110011' //ACCEPT ADDRESS CONTROL CODE
                          //DATA HIGH, CLOCK HIGH
                          //GO INTO I/O ROUTINE 'ERTRAN'
                   
                   
//*********************************************************
//*********************************************************                   
//**  TRANSFER DATA OR ADDRESS TO OR FROM THE ER1400     **
//**            ON ENTRY                             **
//**                --------                             **
//**    FSR (F4) - POINTS TO START OF INFORMATION FILE   **
//**           (CONAD1 IF ADDRESS, DATA1 IF DATA)        **
//**  FILE COUNT - NUMBER OF ER1400 CLOCK CYCLES OR BITS **
//**           W - ER1400 CONTROL CODE                   **
//*********************************************************
//*********************************************************

ERTRAN RES 0
       MOVWF  IOREG       //OUTPUT CONTROL WORD
       MOVLW  .8          //OUTPUT 8 BITS BEFORE
       MOVWF  TEMP        //MOVING TO NEXT INFO FILE.
STLOOP RES 0
       BSF IOREG,ERCLK    //SET THE EAROM CLOCK BIT.
       BTFSC IOREG,C2     //INPUTTING TO THE PIC?
      GOTO RECEIV        //YES, INPUT TO PIC FROM ER1400.
GIVE   RES 0              //ELSE, OUTPUT DATA FROM
       BSF IOREG,ERDATA   //PIC TO EAROM
      RRF 0              //ROTATE INFO FILE INTO CARRY
       SKPC               //IS THE INFO BIT A ZERO ? (?)
      BCF IOREG,ERDATA   //YES, SHIFT A ZERO TO EAROM.
       GOTO NEXTI         //GET NEXT INFO BIT.
RECEIV RES 0              //RECEIVE ‘DATA FROM EAROM.
       BSF IOREG,ERDATA   //ENSURE PIN NOT LATCHED AT ZERO
      CLRC               //READ THE INPUT FROM EAROM
       BTFSC IOREG,ERDATA //IS IT A LOGIC '1°?
      SETC               //YES
       RRF 0              //STORE THE DATA INTO PIC.
NEXTI  RES 0
       BCF IOREG,ERCLK    //CLEAR THE ERAROM CLOCK BIT
       DECFSZ TEMP        //DONE 8 BITS YET?
      GOTO STPAD         //NO, MORE TO GO
       BSF TEMP,3         //ELSE, RESET COUNTER TO EIGTH.
      INCF FSR           //INCREMENT FSR TO NEXT INFO FILE.
FINL?  RES 0
       DECFSZ COUNT       //FINISH ALL INFO FILES ?
      GOTO STLOOP        //NO.
       BSF IOREG,ERCLK    //ELSE, SET EAROM CLOCK BIT HIGH.
      RETLW 77           //END OF EAROM I/O WITH 77 IN W.
STPAD  RES 0
       GOTO FINL?         //TIMING COMPENSATION.
      
      END


Now i need to cross reference the instruction set between the PIC1650 and for instance a PIC16F819. There are a few instruction mnemonics that I dont recognise (SKPC,SETC, CLRC and RES specifically). Maybe there are equivalents or the there is a work around? What are your thoughts?
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Dec 18, 2022 12:40 pm     Reply with quote

around page 68ish of the manual the code is in !

SKPC is skip if the carry bit is set
SETC is set the carry bit
CLRC is clear the carry bit

these probably have equivalents..


RES =?? ,maybe REServe ?? seems it's the start of a 'function', a 'place holder' ?
I didn't see any code actually generated (seen to the left of it...)

hmm.
this...
WMID RES 0
XORWF IOREG //TOGGLE THE EARROM CLOCK
BIFSC COUNT,0
RETLW .14 //RETURN TO CALLING ROUTINE.


BIFSC should be BTFSC

change the I to a T.

It's hard for me to seen pale green on white (dinosaur's eyes....)

other things are
actual address of PORTA for your new PIC
also RAM locations for the variables.

I'm sure others will reply with what they can see...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group