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.

Microchip C18 - How to Access Static Variable

Status
Not open for further replies.

Techtone

Newbie level 4
Joined
May 25, 2010
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
South East England
Activity points
1,359
Hi,

I am working on a project using Microchip P18F2455.

In my project I have several source files, including one named irqhigh.c which handles a timer interrupt.

My main source file is called main.c.

I am at a loss knowing how to declare a variable which can be accessed by both of the source files. Basically, I need to set a variable upon detection of a button press by the debounce routine in irqhigh.c, I then need to be able to read the same variable from the code in main.c.

I have looked at #pragma udata directive and the static keywords, but am just at a loss as to knowing how and where to declare this variable I need.

Sorry if it seems a daft question. I am new to C and Microchip C18, but have many years of PIC assembler experience.

Thanks in advance for any suggestions.

Tony
 

You have to define that variable as extern in both of the files.

ie.
Code:
extern unsigned char varName;
 
  • Like
Reactions: Tagli

    Techtone

    Points: 2
    Helpful Answer Positive Rating

    Tagli

    Points: 2
    Helpful Answer Positive Rating
Static variables are only accessed within the same file.
--
Amr
 

    Techtone

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top