473,566 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pointer to structure array from main.c?


Hi,
I have a keypad that I am scanning to get key states, and am putting
those states in a structure. 16 keys, so I have it like
keys[0].status=PRESSSE D. to keys[16].status etc.

I can access the elements in keypad.c, but why can't I see it from
main.c? It says I need a pointer type, but I can't figure it out yet.

Can someone show me how to access my key information from main.c?
Thankyou. Here are relevant files

*************** ******main.c*** *************** *************** **
#include "includes.h " //which includes keypad.h
//KEY *pKey; //commented out
//pKey = &keys;
//*pKEY = &KEY;

//init I/O for keypad
keypad_init();
while(1){
temp =scankeypad();
temp =scankeypad();
if(keys(1).stat us==KEYPRESSED) {// ***This line gives me an error,
wheras in the keypad.c file I can access this. Gives, must have a
pointer to type function.
fprintf(pntr1, "Key1presse d");
}else{
fprintf(pntr1, "Key1Notpressed ");
}

}
*************** *******keypad.h *************** *************** ***/

#include <includes.h>

#ifndef __KEYPAD_H
#define __KEYPAD_H
#define KEYDOWN 1
#define KEYUP 0
#define MAXDOWNCOUNT 100
#define KEYPRESSED 1
#define KEYNOTPRESSED 0

typedef struct keys {
unsigned char state;
unsigned int downcount;
unsigned char status;
}KEY;
typedef enum {//BIT POSITIONS OF KEYS IN keysdown
UP = 0, //SW4
DOWN, //SW8
ENTER, //SW12
BACK, //SW16
SW5,
SW9,
SW13,
SW17,
SW6,
SW10,
SW14,
SW18,
SW7,
SW11,
SW15,
SW19,
STRIPSWITCH
} keyname;
/* Declare functions */
void keypad_init(voi d);
unsigned int scankeypad(void );
//void getStatusForKey (struct key *pkey);
#endif

*************** *******keypad.C *************** *************** ***/

#include "keypad.h"
/*************** *************** *************** **************
* Function:
*
*************** *************** *************** **************/

//setup I/O of matrix. Internal Pullups on Rows which are inputs.

#define row0 (1<<16)
#define row1 (1<<17)
#define row2 (1<<18)
#define row3 (1<<19)
#define col0 (1<<20)
#define col1 (1<<21)
#define col2 (1<<22)
#define col3 (1<<23)

void keypad_init(){

IO1DIR |= 0x00f00000;//make rows inputs and columns outputs
1=output, 0 = input
IO1DIR &= 0xfff0ffff;//make columns outputs

//FIO1DIR2 is bits16-23 of port1 which are the rows and columns
//Set all high, and pull columns low to see which row key is
pressed.
/*
P1_16 // Row0 = GPIO
P1_17 // Row1 = GPIO
P1_18 // Row2 = GPIO
P1_19 // Row3 = GPIO

P1_20 // Col0 = GPIO
P1_21 // Col1 = GPIO
P1_22 // Col2 = GPIO
P1_23 // Col3 = GPIO
*/
/*while(1){

IO1CLR |= (col0 | col1 | col2 | col3);
}*/
}//keypad_init
unsigned int scankeypad(void ){
unsigned int keysdown=0;
unsigned int temp=0;
unsigned char colbit, rowbit,keybit=0 ;

KEY keys[10];

IO1SET |= (col0 | col1 | col2 | col3);// set all columns high at
first

for(colbit=20;c olbit<24;colbit ++){
IO1CLR |= (1<<colbit);//set a column low

for(rowbit=16;r owbit<20;rowbit ++){
temp=(IO1PIN & (1<<rowbit));
if(temp==0){//if this row is low update keysdown
keysdown |= (1<<keybit); //place 1's in down key positions,
bit0 is first scanned
keys[keybit].state=KEYDOWN;
if(keys[keybit].downcount<MAXD OWNCOUNT ){
keys[keybit].downcount++;
}else{
if(keys[keybit].downcount==MAX DOWNCOUNT){
keys[keybit].status=KEYPRES SED;
}
}
}else{ //key is up
keysdown =keysdown & ~(0<<keybit);//place 0's in up keypad bit
positions
keys[keybit].status=KEYNOTP RESSED;
keys[keybit].downcount=0;
keys[keybit].state=KEYUP;
}
keybit++;
}
IO1SET |= (1<<colbit);//set the column back high
}
return keysdown;
}
Mar 30 '07 #1
3 1577
"Steve" <sr*@nosapm.com schrieb im Newsbeitrag
news:qg******** *************** *********@4ax.c om...
>
Hi,
I have a keypad that I am scanning to get key states, and am putting
those states in a structure. 16 keys, so I have it like
keys[0].status=PRESSSE D. to keys[16].status etc.

I can access the elements in keypad.c, but why can't I see it from
main.c? It says I need a pointer type, but I can't figure it out yet.

Can someone show me how to access my key information from main.c?
Thankyou. Here are relevant files

*************** ******main.c*** *************** *************** **
#include "includes.h " //which includes keypad.h
//KEY *pKey; //commented out
//pKey = &keys;
//*pKEY = &KEY;

//init I/O for keypad
keypad_init();
while(1){
temp =scankeypad();
temp =scankeypad();
if(keys(1).stat us==KEYPRESSED) {// ***This line gives me an error,
if (keys[1].status==KEYPRE SSED) { /* need to use [], not ()*/
/* Beginning of main() is missing as well as an extern KEY keys[]; */
wheras in the keypad.c file I can access this. Gives, must have a
pointer to type function.
fprintf(pntr1, "Key1presse d");
}else{
fprintf(pntr1, "Key1Notpressed ");
}

}
*************** *******keypad.h *************** *************** ***/

#include <includes.h>

#ifndef __KEYPAD_H
#define __KEYPAD_H
#define KEYDOWN 1
#define KEYUP 0
#define MAXDOWNCOUNT 100
#define KEYPRESSED 1
#define KEYNOTPRESSED 0

typedef struct keys {
unsigned char state;
unsigned int downcount;
unsigned char status;
}KEY;
typedef enum {//BIT POSITIONS OF KEYS IN keysdown
UP = 0, //SW4
DOWN, //SW8
ENTER, //SW12
BACK, //SW16
SW5,
SW9,
SW13,
SW17,
SW6,
SW10,
SW14,
SW18,
SW7,
SW11,
SW15,
SW19,
STRIPSWITCH
} keyname;
/* Declare functions */
void keypad_init(voi d);
unsigned int scankeypad(void );
//void getStatusForKey (struct key *pkey);
#endif

*************** *******keypad.C *************** *************** ***/

#include "keypad.h"
/*************** *************** *************** **************
* Function:
*
*************** *************** *************** **************/

//setup I/O of matrix. Internal Pullups on Rows which are inputs.

#define row0 (1<<16)
#define row1 (1<<17)
#define row2 (1<<18)
#define row3 (1<<19)
#define col0 (1<<20)
#define col1 (1<<21)
#define col2 (1<<22)
#define col3 (1<<23)

void keypad_init(){

IO1DIR |= 0x00f00000;//make rows inputs and columns outputs
1=output, 0 = input
IO1DIR &= 0xfff0ffff;//make columns outputs

//FIO1DIR2 is bits16-23 of port1 which are the rows and columns
//Set all high, and pull columns low to see which row key is
pressed.
/*
P1_16 // Row0 = GPIO
P1_17 // Row1 = GPIO
P1_18 // Row2 = GPIO
P1_19 // Row3 = GPIO

P1_20 // Col0 = GPIO
P1_21 // Col1 = GPIO
P1_22 // Col2 = GPIO
P1_23 // Col3 = GPIO
*/
/*while(1){

IO1CLR |= (col0 | col1 | col2 | col3);
}*/
}//keypad_init
unsigned int scankeypad(void ){
unsigned int keysdown=0;
unsigned int temp=0;
unsigned char colbit, rowbit,keybit=0 ;

KEY keys[10];

IO1SET |= (col0 | col1 | col2 | col3);// set all columns high at
first

for(colbit=20;c olbit<24;colbit ++){
IO1CLR |= (1<<colbit);//set a column low

for(rowbit=16;r owbit<20;rowbit ++){
temp=(IO1PIN & (1<<rowbit));
if(temp==0){//if this row is low update keysdown
keysdown |= (1<<keybit); //place 1's in down key positions,
bit0 is first scanned
keys[keybit].state=KEYDOWN;
if(keys[keybit].downcount<MAXD OWNCOUNT ){
keys[keybit].downcount++;
}else{
if(keys[keybit].downcount==MAX DOWNCOUNT){
keys[keybit].status=KEYPRES SED;
}
}
}else{ //key is up
keysdown =keysdown & ~(0<<keybit);//place 0's in up keypad bit
positions
keys[keybit].status=KEYNOTP RESSED;
keys[keybit].downcount=0;
keys[keybit].state=KEYUP;
}
keybit++;
}
IO1SET |= (1<<colbit);//set the column back high
}
return keysdown;
}

Mar 30 '07 #2
On Fri, 30 Mar 2007 09:30:35 -0400, Steve <sr*@nosapm.com wrote:
>
Hi,
I have a keypad that I am scanning to get key states, and am putting
those states in a structure. 16 keys, so I have it like
keys[0].status=PRESSSE D. to keys[16].status etc.

I can access the elements in keypad.c, but why can't I see it from
main.c? It says I need a pointer type, but I can't figure it out yet.

Can someone show me how to access my key information from main.c?
Thankyou. Here are relevant files
Joachim, Thankyou very much. I totally missed that () as opposed to
[]. I did have the extern up top at one point, but I can't believe
you caught that subtle error.
Thankyou,
Steve (I accidentally deleted the response by mistake, but I did get
and compile it now.)
Mar 30 '07 #3
"Steve" <sr*@nosapm.com schrieb im Newsbeitrag
news:7s******** *************** *********@4ax.c om...
On Fri, 30 Mar 2007 09:30:35 -0400, Steve <sr*@nosapm.com wrote:
>>
Hi,
I have a keypad that I am scanning to get key states, and am putting
those states in a structure. 16 keys, so I have it like
keys[0].status=PRESSSE D. to keys[16].status etc.

I can access the elements in keypad.c, but why can't I see it from
main.c? It says I need a pointer type, but I can't figure it out yet.

Can someone show me how to access my key information from main.c?
Thankyou. Here are relevant files

Joachim, Thankyou very much. I totally missed that () as opposed to
[]. I did have the extern up top at one point, but I can't believe
you caught that subtle error.
I've made enough of these mistakes myself 8.)

Bye, Jojo
Mar 30 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2240
by: firegun9 | last post by:
Hello everyone, here is my program: /////////////////////////////// #include <iostream> using namespace std; void multi(double* arrayPtr, int len){ for(int i=0; i<len; i++) *(arrayPtr+i)*=2;
11
2081
by: Edd | last post by:
Hello all, I've made a data structure and an associated set of functions to enable me to store a dynamically-sized array of elements of whatever data type I like. Well that's the idea anyway... My implementation seems to work great for primitive types, structures and unions, but I can't quite get an array of function-pointers working...
20
2060
by: j0mbolar | last post by:
I was reading page 720 of unix network programming, volume one, second edition. In this udp_write function he does the following: void udp_write(char *buf, <everything else omitted) struct udpiphdr *ui; struct ip *ip; ip = (struct ip *) buf;
204
12937
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 = {0,1,2,4,9};
5
2305
by: caleb.vandyke | last post by:
I am working with some code that is doing some pointer to structure casts and I can't figure out how the cast is being done. Here is basically the code. #include <stdio.h> #include <stdlib.h> typedef struct diffRecord { struct record *next;
7
2795
by: Kathy Tran | last post by:
Hi, Could you please help me how to declare an araay of pointer in C#. In my program I declared an structure public struct SEventQ { public uint uiUserData; public uint uiEvent; public uint uiParam0; public uint uiParam1;
7
2089
by: Paminu | last post by:
In the following code I am trying to initialize a pointer that is located in a struct. #include <stdlib.h> #include <stdio.h> #define KIDS 4 typedef struct test { void *content;
8
2389
by: Sam | last post by:
I have a situation occuring in my code and I just can't see to figure out why I have an structure called employee that will put all of the employee id's into a char array set to 10 struct Employee { char employeeid; /* id of employee*/
17
3226
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ================================================================================ /* A function that returns a pointer-of-arrays to the calling function. */ #include <stdio.h> int *pfunc(void);
12
3861
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that looked sensible, but it didn't work right. Here is a simple example of what I'm trying to accomplish: // I have a hardware peripheral that I'm...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.