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.

pic12c508A Toggle a LED

Status
Not open for further replies.

Gayan Soyza

Active Member
I wrote a simple program in pic 12c508a to toggle a led with a push button.

*led is connected to GP0
*button is connected to GP3
*every time the button press the led toggles.

My ques is here i'm using an internal rc oscillator.i didn't calibarate the
oscillator value.is this coding correct.i need to calibarate this for 4mhz.
how the program comes?

all the time i used external rc oscillators in 16f84a this is my first with internal ones.I went through the PDF it just tells briefly,no codings given.


Start ORG 0x00
BSF 03,5 ;Go to page1 for setting-up the ports
MOVLW 3Eh ;Make GP3 Input
MOVWF 06h
BCF 03,5 ;Go to Page0 for programming

SwLoop1 BTFSC 06,3 ;Is switch A pressed?
GOTO SwLoop1 ;YES. Go to SwLoop1
CALL DELAY
SwLoop2 BTFSS 06,3 ;Is switch A pressed?
GOTO SwLoop2 ;NO. Go to SwLoop2
MOVLW 01 ;YES.
XORWF 06,1 ;Toggle the LED
CALL DELAY
GOTO SwLoop1

DELAY DECFSZ 1Bh,1
GOTO DELAY
DECFSZ 1Ch,1
GOTO DELAY
RETLW 00

END
 

Attachments

  • Coding.JPG
    Coding.JPG
    29 KB · Views: 832
Last edited:
I suggest you try using the MicroChip include files, it makes no sense using the numeric values for registers rather than their names from the include files.

Also use the 'code' button (click on 'go advanced' to enable it) to surround your code, this maintains it's formatting.

As it is, poorly formatted, and no register names, it makes it difficult to read, there's also no config fuse settings included in the file.
 
hey Gayan Soyza, I have knocked up this for you to take a look at, this might hopefully clear up some issues for you. You can compile it in Mpasm (part of the MPlab IDE - free from Microchip)
This is real newbie code, so no comments about how it can be optimised from the more experienced programmers please, it's purpose is purely educational.
 

Attachments

  • Forum2.zip
    4.5 KB · Views: 348
since your toggleing an LED when a button is pressed don't worry about the cal. osc. it really doesn't matter. If you really concered about timing the internal RC is the worst pick. The accuacy is horable. use a 32khz crystal for clock application works best
 
I beg to differ, the accuracy is good on the internal rc oscillator as long as you use the factory calibration settings. It's the temperature drift and supply variations that fark it up. The accuracy is good enough to be useable for Manchester encoding/decoding of a serial bit stream at 14400bps, so it's plenty accurate enough for most general tasks.

If on the other hand, you would be wanting to use it for really accurate timing measurements, say for use as a frequency counter for example, then you would not naturally choose an oscillator set-up that has an order of magnitude less stability than what you are trying to measure.
 
Pic12c508

I'm unable to load the program to 12c508. I do not know what is this oscilator calibration value is. Can some one help please.
Thanks
 
I am new member please any one can help me to write a simple program for 12C508. That is to work two inputs like "AND Gate" but output should come ON after 30s delay. after the any input become 0, the should go OFF reverse way after 30s. Thanks. Amin
 
pic12c508A as a AND gate & time delay

I am new member please any one can help me to write a simple program for 12C508. That is to work two inputs like "AND Gate" but output should come ON after 30s delay. after the any input become 0, the should go OFF reverse way after 30s. Thanks. Amin
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top