Continue to Site

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.

  • 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.

Help with simple code for 12c508a

Status
Not open for further replies.

DrZeus

New Member
I would really appreciate anyone’s help they can give on a very simple task I need to perform. I have been trying to read up on programming the 12c508a (have some lying around with programmer) but not getting very far.

I have a device (amp) with a stand-by power of 3.3v that has a momentary on push button to switch it on. What I want to do is power it on from the wall socket without pushing the button, like this:

switch device on at the wall socket (mains) ->
device is in stand-by 3.3v is on->
pic becomes active ->
wait 500ms ->
3.3v for 200ms to one side of switch (switch device on) ->
pic turn off/sleep/quit


Can anyone help me with code for this?
Cheers
 
I suggest you check the PICList delay code generator, that will generate accurate delays for you - you then just need to string them tgether!.

BTW, I presume you know the 12C508A is an OTP chip?, you can only write to them ONCE.
 
Have only programmed a little before, never in asm and after reading all day, 8 hrs later my eyes are starting to bleed!

I have managed to tack this together and think it is ok, help with it would be great. I take it I can just assemble it now and burn? Do I need to 'stop'/end the program? I have a sleep command but not sure if it continues running.

I am using 12c508a as they are free and have a whole pile of them. Hopefully wont waste too many before it works ;)
Thanks


Code:
SetUp   BSF 03,5        ;Select page1
           MOVLW 3E        ;Make GP0 output
           MOVWF 06h       ;Load TRISB file
           BCF 03,5        ;Select page 0
           GOTO Main

Delay    MOVLW 03        ;Delay 500ms
           MOVWF 0E
           MOVLW 00
           MOVWF 0C
           MOVWF 0D

DelA     DECFSZ 0C,1
           GOTO DelA
           DECFSZ 0D,1
           GOTO DelA
           DECFSZ 0E,1
           GOTO DelA
           RETURN

Main     CALL Delay	   ;Wait 500ms
           MOVLW 01        ;Load W with 1
           MOVWF 06        ;Move W to file 06 (GP0 High)
           CALL Delay        ;Create ON time
           MOVLW 00 
           MOVWF 06       ;GP0 Low
          
           BCF OPTION,7   ;Enable GPWU 
           MOVF 06,1 
           SLEEP   	      ;Sleep
 
You will find it a LOT easier (and so will we!) if you use the MicroChip include names - like 'GPIO' for the port address, 'STATUS' for the status register, and the bit name of the flag you want to set.
 
Hi there,

As good practice it's always better to but the end command in at the end of your program.

As far as your code goes it look all ok to me. Just one point for future reference,

Instead of using the commands,

MOVWF 0E
MOVLW 00

It would be better coding if you just use the command

CLRF 0E

This is better for a number of reasons,

1) It makes you code a little smaller.
2) In bigger programs where timing is critical this way would make your program much faster compared to the other method.

All the best

Pete
 
The movlw 0 would only need to be executed once. Then one can using multiple movwf instructions to clear registers.

Using CLRF will destroy(SET) the Zero flag while the two-instruction pair will leave the zero flag intact, which could come in handy in some very rare circumstances.
 
Well thanks for your help and advice so far, I am making progress but just hit a bit of a snag.

Altered the code slightly to get it to run and it does so fine. To test it works I run the pic off 5v with an LED on output pin and it works great, timing is good. Problem is when I connect it in the device to be switched on, it has 3.3v standby power. This would be Ok i thought as I looked at the datasheet for 12c508a and it says 3v-5.5v. Problem is I get nothing, the chip does not seem to be getting enough power. Tested and verified there is 3.3v there, all ok.

Is it likely the datasheet is a rough voltage or should it work on 3.3v? Possibly something else I'm doing wrong?

Cheers
 
The datasheet states that it should work fine down to 2.5V. Could it be that your LED has a high forward voltage and therefore doesn't light?

Mike.
 
how clean the supply line is? how about if you add a 0.1uF close to your PIC... maybe also a 10uF tantalum too.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top