Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC12f683 C-code programming

Status
Not open for further replies.

imranahmed

Advanced Member level 3
Joined
Dec 4, 2011
Messages
817
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Karachi,Pakistan
Activity points
6,492
Please let me know that how to use ports of pic12f683 in C-language.
Please share any example or hint or references.Attached code but this is not working.Programming in mikroc C Pro for PIC.
 

Attachments

  • code.txt
    170 bytes · Views: 226

Here is some old code I found on my hard drive.

Might give some clues....

Code:
// simple LED test - for PIC12F683
// set internal oscillator in configuration bits
// make sure project frequency matches the frequency set below with OSCCON

void main() {
    OSCCON = 0x51;                      // Internal 2MHz osc.

    ADCON0 = 0;                         // all pins digital
    ANSEL = 0;                          // all pins digital
    CMCON0 = 7;                         // Comparators off.
    TRISIO = 0;                         // all output
    GPIO = 0;                           // all pins low

    while (1){
        GPIO = 0;                       // All LEDs off
        Delay_ms(500);                  // half second delay
        GPIO = 0xff;                    // all LEDs on
        Delay_ms(500);
    }
}

GP3 is an input-only pin, so you will not succeed in flashing an LED with that pin :lol:

Check the datasheet
 
You have to know and remember that the GPIO pins are also multiplexed to the ADC and the analog comparator. To use the GPIO pins/lines as digital IO, you must disable the analog peripherals/modules. Disable them with the following:
Code:
ANSEL = 0;
CMCON0 = 7;

hexreader has shown this in his code and has uploaded a complete code for you to test. Things should be clearer now. :smile:

Hope this helps.
Tahmid.
 
Another thing i want to know that (GP3/MCLR) internally how i use MCLR in software enable or disable?
 

You have to enable/disable it through the configuration settings. In mikroC, go to Project (Alt + P) > Edit Project or press Ctrl + Shift + E. There is an option "MCLR pin function". Select "Disabled" to disable MCLR and use GP3 as digital IO. Select "Enabled" to use MCLR instead of GP3 as digital IO.

Hope this helps.
Tahmid.
 
Please let me know that what is difference between INTOSCIO AND INTOSC
in oscillator selection option and about Brown Out Detect,Internal External Switchover,
Power-up Timer Code and Data Code protection and Fail-Safe Clock Monitor.And
if I define OSC freq. in software it will necessary to define in Edit project option.
 
Last edited:

Check page 86 (and onwards) of the datasheet.

Here is the configuration word:
9007253200_1352797360.png

4343596600_1352797427.png


If you're going to use internal oscillator, you must set so in the configuration settings under "Edit Project".

If you have any questions, feel free to ask.

Hope this helps.
Tahmid.
 
Actually I am beginner for PIC`s.
If I want to use A/D what will i use in CONFIG register
INTOSC OR INTOSCIO and what are the conditions for
using INTOSC and INTOSCIO.I want to make program
for sensing analog voltage and send sensed voltage in
output pin GP0-GP5 except GP3 because its only input
pin.Please share any hint or sample program for using
A/D in PIC12f683.
 

Can i use ADC library function for 12f,16f series or only for 16f series.

Any PIC that is supported by mikroC and has an ADC module. So, you can use it for PIC12 as well.
 
If i want to sense 2.5V in AN0 channel where(GP0-GP5) will i get the output of analog value.

Another question is that i learnt in datasheet of PIC12f683 that development support is MPLAB IDE software.
But what is different between Mikroc and MPLAB IDE.If MPLAB IDE is more easy than mikroc i will use MPLAB otherwise i will use mikroc.Please share with me this information about development support.
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top