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.

PIC18 C Help

Status
Not open for further replies.

Spideys

New Member
Good Day all

This is my first post. I am in need of serious help. I am willing to read up on the info np, but i cant seen to find exactly what I am looking for:

C language, instructions, symbols & syntax for PIC18

I am working on a Smart Battery charging unit that i want to control using a PIC microcontroller.

Just want to get some basics up and running before i start design.

Like example how do i read the state of an input pin ( correctly setup RA0) using C language and PIC18f4331 or PIC18f4520

Any help would be much appreciated ( Going insane here )
:confused:
 

Pommie

Well-Known Member
Most Helpful Member
There are many examples of C18 code on this site. If you look at my profile and the threads I have started, some are C18 related.

To check RA0 you would do,
Code:
    if(PORTAbits.RA0==1){
        //code here
    }

Mike.
 

AtomSoft

Well-Known Member
if you are using C18 from microchip then when its installed goto

C:\mcc18\doc

there are a few documents there with lots of info:

hlpC18Lib.chm - "This section gives an overview of the MPLAB C18 library files and precompiled object files that can be included in an application"

hlpC18ug.chm
- "This document discusses the technical details of the MPLAB C18 compiler. This document will explain all functionality of the MPLAB C18 compiler"

hlpPIC18ConfigSet.chm - "This document lists the configuration settings available for each of the PIC18 devices for use with MPLAB® C18's #pragma config directive and MPASM™ assembler's CONFIG directive. "

PIC18F Peripheral Library Help Document.chm - "The PIC18 MCU Peripheral Library provides a set of functions for setting up and controlling the operation of all the peripheral modules available in the PIC18 devices, as well as functions for interfacing with an external LCD, Software implemented communication modules. "
 

AtomSoft

Well-Known Member
no problem there are a select few here who would help you out a lot if you ask right and actually try to learn yourself also.

If you have a project in mind post about it and post your progress this way we know your intentions are for help not just someone to do it all for you.

pommie code is correct but there are more efficiant ways like define the port pin this way if it needs to be changed you only need to change one line and all will follow:

Code:
#define myButton PORTAbits.RA0

.....

//now you can use 
if(myButton == 1){
    //button pressed do something
}

Note: the above code assumes the button is pulled down meaning a resistor is connected to GND.

If your button is pulled high then use the below code:

Code:
#define myButton PORTAbits.RA0

.....

//now you can use 
if(myButton == 0){
    //button pressed do something
}
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top