• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need Code for 12C508A

Status
Not open for further replies.

ltdedition

New Member
Hello everyone, I'm a complete newbie to code writing and I'm very keen to learn, I do have some experience in flashing PIC's as I have a Pic Programmer and have flashed hex files to PIC16F84's, But this was pre written code from someone else and then as I understand exported to HEX from and ASM file.

The Code I need is for the 12C508A, Which is a controller for another IC ( MC145170P2 ) which is a Phase Lock Loop stabilizer for an FM Transmitter, The 12C508A contains the Data that tells the MC14517OP2 what Frequency the transmitter should be operating on.

I do have a 12C508A at home and when I tried to read it, the code was protected. This 12C508A I have has code written for 107 Mhz. I looked around on some forums and I found that the code was not completely protected, something about the last 64 or something being unprotected,

I do have a hex backup of it, I clicked on a tab in my Pic Programming software saying disassemble I think, But anyway I have an ASM file of something maybe this can help speed up the code writing.

Schematic
View attachment 64061

Data sheet for MC14517OP2 http://www.datasheetcatalog.org/datasheet/motorola/MC145170DT2.pdf

any help with be very grateful,

Thank you
 
Last edited:

Diver300

Well-Known Member
Most Helpful Member
Don't use a 12C508A. You can only programme it once. Use a 12F508 so that it can be programmed lot of times.

What frequency are you wanting to get from the PLL? What is the reference frequency?
 

ltdedition

New Member
Thanks for the advice on using the 12F508, that will be handy for testing code.

The reference frequency is coming from the Oscillator on the TX PCB, which is then fed into the MC14517OP2 detector input. It will then compares it with its reference which is coded into the 12C508A, if the actual frequency from the Oscillator doesn't match is reference code on the 12C508A then the output voltage from the MC14517OP2 will be adjusted to the TX's Varicap diodes unit everything matches..


Hope that make any sence


I think I might need to start a thread about the MC14517OP2
 
Last edited:

Diver300

Well-Known Member
Most Helpful Member
That does make sense, but I already knew how a PLL works.

What is the reference frequency? I am hoping for an answer in Hz.

What is the output frequency that you want if you don't want 107 MHz? Again, I am looking for a number of Hz, or kHz, or MHz.
 

ltdedition

New Member
Well the reference frequency the MC14517OP2 could be looking at, is anything from 87.5 Mhz to 108 Mhz. I do try to tune the oscillator to as near as possible to 107 Mhz, then the MC1451OP2 will be able to stabilizer it, to what is programmed on the 12C508A

Here's a Picture of the TX 87.5-108 Mhz FM Transmitter, This is not my build but another persons.
View attachment 64062

Here's a Picture of the PLL
View attachment 64063

This bloke has the same problem, his 12C508A pic is set to a 102MHz and is trying to make the code as well.

Really the end result is have the codes for all frequencies from 87.5 to 108 MHz

Hope this helps.
 
Last edited:

Diver300

Well-Known Member
Most Helpful Member
I can't read those attachments. There is something wrong with them.

You still haven't said what the reference frequency is. It is probably the number written on the case of the crystal.

The output frequency is 107 MHz, but you want to be able to change that from 87.5 MHz to 108 MHz. That is not the reference frequency.

The MC145170P2 needs a fixed reference frequency, which is compared to the output frequency. The numbers that are programmed into the MC145170P2 depend on the reference frequency.

This is my 4th post on this thread. I have asked for the reference frequency in each one. I am trying to help you here. I know what a reference frequency is, I know what a PLL is, and I might even write a few lines of code for you if you tell me the frequency of the reference.
 

ltdedition

New Member
Think I've fixed the pictures, OK, sorry if I'm not very helpful, I don't mean to be. The Crystal has 4Mhz on it.

This is the schematic for the whole thing, he says to build it in two half's because its easier,

View attachment 64064

has components values which may help things
 
Last edited:

ltdedition

New Member
The reference frequency is 107 Mhz, If I can get the code, I'll have a backup, for when I build my next TX
 
Last edited:

ltdedition

New Member
Thank you very much, I really appreciate that. I brought a 12F627 I think, The man in the shop said it's basically the same as the 12C5xx & 12F5xx. I'm not 100% sure he's right so I brought some 12C508A to be safe. I will get some 12F508A when I find somewhere that sells them.
 

Diver300

Well-Known Member
Most Helpful Member
Here is some untested code.

I have run it through the simulator and that seems to work but I haven't tried it in real life.
You would need to change which registers are used for different processors, but the code will run on most of the pic12 or pic16 series processors.

I think that the outputs are correct for the circuit that you are using, but they can be changed in the definitions at the start of code.

Code:
	include p12F629.inc

Dout			equ	0x00
Dout_port		equ	GPIO

Enb				equ	0x04
Enb_port		equ	GPIO

Clk				equ 0x05
Clk_port		equ	GPIO


Clock_count 	equ	0x20
Out_data_2		equ 0x21
Out_data_1		equ 0x22
Out_data_0		equ 0x23

clock_count2	equ 0x24
Out_data_2_b	equ 0x25
Out_data_1_b	equ 0x26
Out_data_0_b	equ 0x27


	org 0

	clrf	Clock_count
	
	decfsz	clock_count2, f
	goto	$-1

	decfsz	Clock_count, f
	goto	$-3				;startup pause

		
	movlw	0x07
	movwf	CMCON			;turn off comparators

	bsf		STATUS, RP0		;go to bank 1
	
	bcf		Enb_port, Enb
	bcf		Dout_port, Dout	
	bcf		Clk_port, Clk	;enable the outputs

	bcf		STATUS, RP0		;back to bank 0

	bsf		Enb_port, Enb	;start off with the enable line high
	bcf		Clk_port, Clk	;and the clock low

	clrf	Clock_count
	
	decfsz	clock_count2, f
	goto	$-1

	decfsz	Clock_count, f
	goto	$-3				;pause to make sure the PLL has started

	call	reset_PLL



reset_PLL
;With the data line low, and the enable line high
;this needs to clock out 4 cycles

	bcf		Dout_port, Dout	
	bsf		Enb_port, Enb

	movlw	0x04
	movwf	Clock_count

reset_clock_loop
	bsf		Clk_port, Clk
	nop	
	bcf		Clk_port, Clk	

	decfsz	Clock_count, f
	goto	reset_clock_loop

	movlw	0x05
	movwf	Clock_count

	movlw	0x02
	movwf	Out_data_0

	call	data_out		;clock out the remaining 5 bits of the reset sequence

;This outputs 0 to the configuration register
;That is the default so it does nothing but it's here so that other numbers can be output

	movlw	0b00000000
	movwf	Out_data_0

	movlw	0x08
	movwf	Clock_count

	call	data_out

;This now outputs 80 to the reference divider.
;The 15 clock cycles cause it to be addressed to the reference divider
;With a 4 MHz reference and a resolution of 50 kHz, the reference needs to be divided by 80

	movlw	0x0f
	movwf	Clock_count

	movlw	0
	movwf	Out_data_1

	movlw	0x50
	movwf	Out_data_0

	call	data_out

;Now this outputs 2140 to the frequency divider.
;The 16 clock cycles cause it to be addressed to the frequency divider
;2140 x 50 kHz = 107 MHz

	movlw	0x10
	movwf	Clock_count

	movlw	0x08
	movwf	Out_data_1

	movlw	0x5C		;there might be a neat way of getting the assembler
						; to split 2140 into two bytes.
	movwf	Out_data_0

	call	data_out

;that's it
;All the program does now is die
	goto	$			;This needs the watchdog to be disabled


data_out
;the data needs to be msb first, but the length of the data varies.
;So it has to be reversed first

	movf	Clock_count, w
	movwf	clock_count2

data_reverse_loop
;This reverses the Clock_count bits of data into Out_data_n_b
;so that the MSB ends up in the LSB of Out_data_0_b
	rrf		Out_data_2, f
	rrf		Out_data_1, f
	rrf		Out_data_0, f		;rotate data towards LSB

	rlf		Out_data_0_b, f
	rlf		Out_data_1_b, f
	rlf		Out_data_2_b, f		;rotate data towards MSB

	decfsz	clock_count2, f
	goto	data_reverse_loop


	movwf	clock_count2		;collect count again from w

	bcf		Enb_port, Enb		;lower enable line

data_out_loop
;This output data starting with the LSB of Out_data_0_b

	btfsc	Out_data_0_b, 0
	bsf		Dout_port, Dout		

	btfss	Out_data_0_b, 0
	bcf		Dout_port, Dout		;output data

	rrf		Out_data_2_b, f
	rrf		Out_data_1_b, f
	rrf		Out_data_0_b, f		;rotate data to LSB
		
	bsf		Clk_port, Clk
	nop	
	bcf		Clk_port, Clk		;clock data into PLL

	decfsz	clock_count2, f
	goto	data_out_loop

	bsf		Enb_port, Enb		;raise enable line to save data

	return

	end
 

ltdedition

New Member
Thank you very much for the code, I'm just about to get my programmer hooked up, I'll let you know how it goes, Thank you again,
 

ltdedition

New Member
Having a few problems, I've assembled to code okay with Zero error reports :) , But my Pic Programmer doesn't like the 12F675 PIC I brought, I've got a 12F508 being delivered from a component company called cricklewood electronics which will be with me on Monday, Not sure why my programming board doesn't like the 12F675 even thou it has it in the drop down PIC selector tab. I put it in and the Software says PIC doesn't match Programmer configurations. Its not my Programmer Board, because I'm still using it to Flash other pics with no problems, Cant wait till Monday, I really want to test this..:)
 
Last edited:

ltdedition

New Member
I thought I'd just paste this up anyway, Its a snippet of the original code, well not all of it because the PIC was code protected. but I don't understand any of it yet.. I'm just bored really until I get my PIC delivery in post. I disassembled the hex and this is what I've got..

Code:
    #include <p12f508.inc>
processor p12f508

; -----------------------------------------------------------------------
    __CONFIG _IntRC_OSC & _WDT_ON & _CP_ON & _MCLRE_OFF

; -----------------------------------------------------------------------
; code memory
org 0x000
    movwf	0x5
    movlw	0x1e
    movwf	0x10
    call	0x4c
    decf	0, f
    sleep
    dw	0x44  ;unknown opcode
    retlw	0
    clrwdt
    retlw	0
    nop
    iorwf	0x4, w
    clrwdt
    retlw	0
    movwf	0x3
    iorwf	0x4, w
    nop
    clrwdt
    decf	0x3, f
    dw	0xf  ;unknown opcode
    clrwdt
    retlw	0x3
    movwf	0x3
    iorwf	0x4, w
    nop
    clrwdt
    decf	0x3, f
    tris	0x7
    iorwf	0x4, w
    nop
    iorwf	0x4, w
    nop
    clrwdt
    bcf	0x4, 0
    nop
    iorwf	0x4, w
    nop
    clrwdt
    nop
    bsf	0x6, 0x4
    movlw	0x60
    bcf	0x6, 0x4
    call	0x3e
    bsf	0x6, 0x4
    nop
    bcf	0x6, 0x4
    movlw	0x4
    call	0x3e
    movlw	0x2e
    call	0x3e
    bsf	0x6, 0x4
    nop
    bcf	0x6, 0x4
    movlw	0
    call	0x3e
    movlw	0
    call	0x3e
    movlw	0x50
    call	0x3e
    bsf	0x6, 0x4
    clrwdt
    goto	0x3c
    movwf	0x10
    movlw	0x8
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop

; -----------------------------------------------------------------------
; eeprom memory
end
Like I said I'm just board, :), I take it the "nop" is where its code protected..
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top