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.

code to change what is pointed to

Status
Not open for further replies.

winnie mong

Junior Member level 3
Joined
Sep 8, 2013
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
366
hi guys.
thanks a lot for the great help you are giving to me,i appreciate a lot since i am not very good with c programming:)
i have this function below which allows me to make a choice from the scrolling menu composing of three items i.e setting clock time, setting On time and setting Off time for a geyser timer.to set time for the three items, the same routine is followed.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#define EVENT_CLK_TIME 0
#define EVENT_ON_TIME 1
#define EVENT_OFF_TIME 2
 
const char *const menu2[]={
       "CLK TIME",  
       "ON TIME",    
       "OFF TIME",    
       0}; 
 
void do_set_time (){
 
    int event;
    
    event=choice(menu2);                                      //scroll menu1 on display
    
        if(event==EVENT_CLK_TIME)                   //clock time option selected from menu2
            {
                scroll("SET CLK",1);           //pointing to setting clock time
                
            }
        else if(event==EVENT_ON_TIME)             //on time option selected from menu2     
    
            {
                scroll("SET ON TIME",1);          // pointing to setting on time
                              
            }
        else if(event==EVENT_OFF_TIME)                    //off time option selected from menu2  
            {
                scroll("SET OFF TIME",1);           //pointing to setting off time
                              
            }
    }


i want to ask for help in producing a code that will change what is being pointed to in the above code, so i can be able to set time for the option i selected.thanx
 

Post full code.

Change

Code C - [expand]
1
const char *const menu2[]



to


Code C - [expand]
1
const char menu2[] = {"CLK TIME", "ON TIME", "OFF TIME"};



Mention compiler used.
 

ok, i am using MPLAB IDE V8.92 and compiler HCPIC-picc-9.83.
this is the input/output.c file

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "timer.h"
 
char    sbuf[15];
char    line[12];
char    starburst[DISPLAY_DIGITS];
unsigned char   dpos;
unsigned char   pulses, sec, min, hour, t_track;
 
#define smess   (char*)(&sbuf[SCROLL_BUF_LEN])
 
void clock(void);
void cput(unsigned char c);
void scroll(const char *mess, unsigned char ntimes);
void display(const char *message);
void clrscr(void);
char choice(const char *const *menu);
char getch(void);
void delay(unsigned char time); 
char choice(const char *const *fmenu);
 
/************************************************************************************/
/* cput()                                                                           */
/* This routine writes a single byte to the starburst display unit.                 */
/************************************************************************************/
 
void cput(unsigned char c) 
{
    unsigned char   addr;
    
    TRISB=0x00;                             /* port B is now data output to display */
    TRISA=0x00;                             /* port RA4:RA3 is output control RA2:RA0 is output for address */
    addr=SCROLL_BUF_LEN-dpos++;             /* address of segment */
    PORTA=(PORTA&0x18)|(addr&0x03);         /* RA0, RA1 are address of display cell*/
    PORTB=(PORTB&0x80)|(0x7F&c);            /* character to be written */
    if(addr&0x04) {                         /* 1st four characters */
        DISPLAY_WR1();                      /* write pulse */
    } else {                                /* 2nd four characters */
        DISPLAY_WR0();                      /* write pulse */
    }
    starburst[SCROLL_BUF_LEN-addr]=c;       /* debugging remove later */
    TRISA|=0x07;                            /* port A is now input */
    TRISB=0x7F;                             /* port RB7 is output RB6:RB0 is now input */
}
 
/************************************************************************************/
/* display()                                                                        */
/* This routine writes a string of eight characters to the starburst display unit.  */
/************************************************************************************/
 
void display(const char *message)
{
    unsigned char    i,c;
    
    dpos=0;                                 /* first display position */
    for(i=0; i<DISPLAY_DIGITS; i++) {       /* DISPLAY_DIGITS positions to update */
        if(c=*message++) {                  /* if part of message */
            cput(c);                        /* print string until terminator found */
        } else {
            while(i++<DISPLAY_DIGITS) {     /* rest of display area fill with spaces */
                cput(' ');                  /* pad space character for rest of display */
            }
        }
    } 
}
 
/************************************************************************************/
/* getch()                                                                          */
/* This routine reads the pushbutton state and returns the value   .                */
/************************************************************************************/
char getch(void)
{
    return PORTA&0x07;                      /* read the 3 pushbuttons state */
}
 
/************************************************************************************/
/* clrdisplay()                                                                     */
/* This routine clears the starburst display screen                                 */
/************************************************************************************/
 
void clrscr(void) 
{
    display("");                            /* a clear display */
    dpos=0;                                 /* reset display position */
}
 
/************************************************************************************/
/* scroll()                                                                         */
/* This provides a scrolling message a number of times                              */
/************************************************************************************/
 
void scroll(const char *mess, unsigned char ntimes)
{
    unsigned char   stop;
 
    memset(sbuf,' ',SCROLL_BUF_LEN);
    strcpy(smess,mess);                     /* copy message into buffer */
    do {
        mess=sbuf;                          /* point to begin of message */
        do {
            display(mess++);                /* display part of the message */
            stop=pulses+Delay500ms;
            do {
                if(kbhit()) {               /* abort scrolling ? */
                    clrscr();               /* a clear display */
                    return;                 /* yes then bye */
                }         
            } while(stop!=pulses);
        } while(*mess);                     /* until all characters are displayed */
    } while(--ntimes);                      /* until message is displayed ntimes */
    clrscr();                               /* a clear display */
}
 
/************************************************************************************/
/* choice()                                                                         */
/* This a scrolling menu from which user functions can be selected for use          */
/************************************************************************************/
 
char choice(const   char *const *menu)
{
    const   char    *src;
    char    i,j,stop;
 
    for(i=0;i<3;i++) {
        for(j=0;src=menu[j];j++) {              /* get next string to be scrolled */ 
            scroll(src,1);                      /* scroll the menu item message */
            stop=pulses+Delay500ms;
            do {
                if(kbhit()) {                   /* check for keypad activities */
                    clrscr();                   /* clear display */
                    return j;                   /* if yes return with the key code */
                }
            } while(stop!=pulses);
        }
    }
    scroll("--TIMEOUT--",1);                    /* no input for 20 seconds stop processing */
    return(0xFF);                               /* dummy return will never be taken */
}
 
void delay(unsigned char time)
{
    unsigned char   stop;
 
    stop=pulses+time;                           /* stop when stop marker is reached */
    while(stop!=pulses) ;                       /* other wait for stop condition */
}
 
interrupt isr(void)
{
    if(T0IF) {
        ++pulses;
        ++t_track;                              // increment pulses
    if(t_track==160){
        clock();
        t_track = 0;
            }   
        T0IF=0;                                 // reset TMR0 flag
        }   
        
    
 
}
 
void clock(void)
{
    ++sec;
    if(++sec==60){
           min++;
           sec = 0; }
    if(++min==60){
           hour++; }
    if(++hour==24){
        hour=0; }
}


following is the header file


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <htc.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
 
#define _XTAL_FREQ 4194304
#define DISPLAY_DIGITS  4
#define SCROLL_BUF_LEN  DISPLAY_DIGITS-1
#define TRUE    (bit)1
#define FALSE   (bit)0
#define PUSHLOGICF  FALSE                   // pushbutton ON gives logic FALSE
#define PUSHLOGICT  TRUE                    // pushbutton ON gives logic TRUE
#define set()       (RA0==PUSHLOGICT)       // SET pushbutton pressed
#define select()    (RA1==PUSHLOGICT)       // SELECT push button pressed
#define mode()      (RA2==PUSHLOGICT)       // MODE pushbutton pressed
#define kbhit()     ((PORTA&0x07))          // keypad has character?
#define relayon()   (RB7=TRUE)              // relay on
#define relayoff()  (RB7=FALSE)             // relay off
#define RW0_HIGH()  (RA4=1)                 // write vommand line defaulty status
#define RW0_LOW()   (RA4=0)                 // prepare to write on positive edge
#define RW1_HIGH()  (RA3=1)                 // write command line defaulty status
#define RW1_LOW()   (RA3=0)                 // prepare to write on positive edge
#define DISPLAY_WR1()(RW1_LOW();(RW1_HIGH())    // write command to display 1 for 8 alphanumerics
#define DISPLAY_WR0()(RW0_LOW();(RW0_HIGH())    // write command to display 0
#define Delay500ms      8
#define Delay1000ms     16
#define Delay5000ms     80
#define Delay10000ms    160



and finally the part i have done

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <htc.h>
#include "timer.h"
#ifdef XT
    __CONFIG(XT&PWRTEN&WDTDIS);             // config XT
#else
    __CONFIG(0x3ff1);                       // config XT
    #define OPTION OPTION_REG
#endif
 
#define EVENT_CLK_TIME 0
#define EVENT_ON_TIME 1
#define EVENT_OFF_TIME 2
 
bit GeyserFlag;
char GeyserOffTime[4];
char GeyserOnTime[4];
char CurrentTime[4];
 
 
 
extern void cput(unsigned char c);
extern void scroll(const char *mess, unsigned char ntimes);
extern void display(const char *message);
extern void clrscr(void);
extern char choice(const char *const *menu);
extern char getch(void);
extern interrupt isr(void);
extern void delay(unsigned char time); 
extern char choice(const char *const *fmenu);
extern char sbuf[15];
extern char line[13];
extern unsigned char sec, min,hour, pulses;
char state;
const char *const menu1[]={
       "SET TIME",
       "VIEW TIME",
       0};
 
const char *const menu2[]={
       "CLK TIME",  
       "ON TIME",    
       "OFF TIME",    
       0};     
       
void geyser_state_check();
void do_set_time ();
void display_current_time( );
void do_view_time ();
 
/*************************************************************************************************************************************************/
/*main()                                                                                                                                         */   
/*************************************************************************************************************************************************/
main()
{
  INTCON=0x20;                  // TMR0 allowed to interrupt
    OPTION=0x07;                // prescaler 1:128 to TMR0, enable pullup resistors on PORTA
    TRISB=0x00;                 // RB7 is input RB6:RB0 are inputs
    TRISA=0x07;                 // port A RA2:RA0 input
    pulses=0;
    GIE=1;                      // enable all interrputs
    TMR0IE=1;
    RW0_HIGH(); RW1_HIGH();     // hold WR high to prevent writing to display
    TRISA=0x00;
    sec, min,hour, state = 0;   //initialise time at 0
//  CurrentTime = 1200;
 
 
 
    char j;
    clrscr();
    while (1)
    {
            switch (state)                                                                       //testing variable state
            {
                case 0:
                    geyser_state_check();
                    if (mode()){                                                                 //mode button pressed
                        state=1;                                                                 //update state to 1
                    }
                    display_current_time();                                                      //show current time on display
                    break;
                case 1:
                    j = choice(menu1);                                                           //scroll menu1 on display
                    if (menu1[j]=="SET TIME"){                                                   //set time option selected from menu1
                        do_set_time();                                                           //call set time function 
                    break;
                    }
                    else if(menu1[j]=="VIEW TIME"){                                              //view time option selected from menu1
                        do_view_time();                                                          //call view time function
                        break;
                    }
                    else {
                        state=0;                                                                 //update state to zero
                    }
                    break;
            }
        
    }
}   
 
/*************************************************************************************************************************************************/
/*void geyser_state_check()                                                                                                                      */
/*This routine determines the state of the geyser by comparing its set on or off times with the system clock                                                                                                                                               */   
/*************************************************************************************************************************************************/
void geyser_state_check(){           //geyser state check function definition
 
    
    if(GeyserFlag){                                                                             //Flag is on: ie Geyser is on
    
        if(strcmp(GeyserOffTime, CurrentTime) == 0);                                            //GeyserOffTime and CurrentTime are the same
            {
                GeyserFlag = 0;                                                                 //switch the geyser off
                relayoff();
            }                                                                                   //end if
            
    }                                                                                           //end if
    
    else
    {                                                                                            //if Flag is off: ie Geyser is OFF
        if(strcmp(GeyserOnTime, CurrentTime) == 0);                                              //GeyserOnTime and CurrentTime are the same
            {
                relayon();                                                                       //switch the geyser off
                GeyserFlag = 1;                                
    
            }                                                                                    //end if
    }                                                                                            //end else
}
 
/*************************************************************************************************************************************************/
/*void display_current_time ()                                                                                                                   */
/*This routine updates the clock on the display                                                                                                                                               */   
/*************************************************************************************************************************************************/
void display_current_time()
{
    display(CurrentTime);                                                                         //show current time on display
}   
 
/*************************************************************************************************************************************************/
/*void do_set_time()                                                                                                                             */
/*                                                                                                                                               */   
/*************************************************************************************************************************************************/
void do_set_time (){
 
    int event;
    
    event=choice(menu2);                                                                           //scroll menu1 on display
    
        if(event==EVENT_CLK_TIME)                                                                  //clock time option selected from menu2
            {
                scroll("SET CLK",1);
                
            }
        else if(event==EVENT_ON_TIME)                                                              //on time option selected from menu2     
    
            {
                scroll("SET ON TIME",1);
            }
        else if(event==EVENT_OFF_TIME)                                                             //off time option selected from menu2  
            {
                scroll("SET OFF TIME",1);
            }
    }
//} 
//the three parameters will have same code, and what is being pointed to will 
//be executed in the main code.
 
void do_view_time (){
 
    scroll("VIEW TIME",1);
}

 

alright, how do i attach the zipped file here?
 

i have attached it, hpe u find it.
 

Attachments

  • Programmable Timer.zip
    112.4 KB · Views: 40

i will be handing in report for the timer on 22nd. your help will be highly appreciated b4 then.thank u..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top