CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

problem with returning to main program

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
wael_007



Joined: 30 May 2010
Posts: 5

View user's profile Send private message

problem with returning to main program
PostPosted: Sun May 30, 2010 12:10 pm     Reply with quote

Well I did this code but when I see that it stays in the function (affichage()) doing it from the first and don't return to main to continue.
Code:

#include <16F877.h>
#device adc=8
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#include <math.h>
#include <string.h>
#include <lcd1.c>
#include<clavier16T.c>
#define Bouton1 PIN_C3 //declaration de bouton 1
#define BOUTON2 PIN_C4
#define use_portd_kbd;#endif
//declaration de bouton 1
byte value ;
byte a ;
long int r;void affichage(int n)
{
char value1000;
char value100;
char value10;
char value1,v[10];
char position[10];
int k;int c;int *g;
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RT CC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1) ;
port_b_pullups(true);
lcd_init();
kbd_init();
lcd_gotoxy(1,1);
lcd_putc("\fbienvenue ...\n");
lcd_putc("enterez positions");
delay_ms(2000);

start:;
{
printf(lcd_putc,"\fposition n:%d",n,'\n');
DO
{
value1000=kbd_getc();
} while(value1000==0 );
lcd_putc('\f');
lcd_gotoxy(1,1);
if (value1000=='*' || value1000=='+' || value1000=='-'||value1000=='c'||value1000== '/'||value1000=='='||value1000== '9'||value1000=='8') goto start;

else
lcd_putc(value1000);
do
{
value100=kbd_getc();
} while(value100==0);
lcd_gotoxy(2,1);
if (value100=='*' || value100=='+' || value100=='-'||value100=='c'||value100=='/'||value100=='=') goto start;

else lcd_putc(value100); do
{
value10=kbd_getc();
} while(value10==0);
lcd_gotoxy(3,1);
if (value10=='*' || value10=='+' || value10=='-'||value10=='c'||value10=='/'||value10=='=') goto start;

else lcd_putc(value10); do
{
value1=kbd_getc();
} while(value1==0);
lcd_gotoxy(4,1);
if (value1=='*' || value1=='+' || value1=='-'||value1=='c'||value1=='/'||value1=='=') goto start;

else lcd_putc(value1);
lcd_putc("enregistrer ou effacer");
do
{ k=kbd_getc();
}while(k==0);
if(k=='*')
{n=n+1;goto start;}
else if(k=='+') {goto start;}}
if(k=='-') lcd_putc('\f'); lcd_putc(n); while(true);
}

void main()
{
byte s,a,h;
int k;
long int r;
char v[10];
r=500;a=1; // initialisation de r et a
output_c(0xF8); // le port RC
set_tris_c(0xF8); // configuration do PORT C (1111 1000) ==> RC7,RC6,RC5,RC4,RC3:entrées RC2,RC1,RC0: sorties
setup_adc_ports(NO_ANALOGS); // configuration du convertisseur analogique numérique de PIC : il n ya aucune entrée analogique
setup_adc(ADC_OFF); // mettre en arret le convertisseur analogique numérique de PIC
setup_spi(FALSE); // mettre à l'arret l'interface de communication série du PIC
setup_timer_0(RTCC_INTERNAL|RT CC_DIV_1); // configuration de l'horloge interne du timer0 du PIC sur la fréquence RTCC_DIV_1 , c'est à dire 4MHZ divisé par 1
setup_timer_2(T2_DIV_BY_16, 127, 1); // configuration de l'horloge interne du timer2 du PIC : regarde la formule dans le help de picc
port_b_pullups(true);
//initialisation du lcd
do {h=1;
affichage(h);
k=kbd_getc();}while(k==0);
if(k=='-')
lcd_putc("enter speed");

if (input(bouton1) ==0) { s=1; lcd_gotoxy(7,2);a=0; // si le bouton 1 est appuyé alors aller aux cordonnées (x=7,y=2), c'est à dire deuxiéme ligne, septiéme case de lcd
printf(lcd_putc,"sens avant");delay_ms(500);} // et afficher "sens avant"
if (input(bouton2) ==0) { s=0;lcd_gotoxy(7,2);a=0; // si le bouton 2 est appuyé alors aller aux cordonnées (x=7,y=2), c'est à dire deuxiéme ligne, septiéme case de lcd
printf(lcd_putc,"sens ariere");delay_ms(500);
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun May 30, 2010 1:25 pm     Reply with quote

Quote:
I see that it stays in the function affichage()

Yes, it's exactly written this way. If the code flow possibly overcomes all gotos and reaches the function's end, it's caught for ever by a while(true) statement. Unfortunately, I can't guess, what you are trying to achieve here.
wael_007



Joined: 30 May 2010
Posts: 5

View user's profile Send private message

PostPosted: Mon May 31, 2010 7:19 am     Reply with quote

Well I want to enter 4 numbers between 0 and 8000 by a 16*16 keypad and display them and save them in eeprom as binary numbers, and a not string in order to compare them after with other numbers.
My problem here is that I added a simple instruction in main just after the function (affichage()) but it doesn't work.
plizz help me
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon May 31, 2010 10:08 am     Reply with quote

Code:
if (input(bouton2) ==0) { s=0;lcd_gotoxy(7,2);a=0; // si le bouton 2 est appuyé alors aller aux cordonnées (x=7,y=2), c'est à dire deuxiéme ligne, septiéme case de lcd
printf(lcd_putc,"sens ariere");delay_ms(500);
First thing to do is clean up your code layout. The fragment above is giving me headaches and is the worst example of 'how not to write code' I've ever seen.

A few guidelines are:
- Only one command on a line
- use indentation
- Split long comments over lines

Applying these to the code makes it look like:
Code:
if (input(bouton2) ==0)
{
    s=0;
    lcd_gotoxy(7,2);
    a=0;                // si le bouton 2 est appuyé alors aller aux cordonnées (x=7,y=2),
                        // c'est à dire deuxiéme ligne, septiéme case de lcd
    printf(lcd_putc,"sens ariere");
    delay_ms(500);
}



The code below is there two times, but slightly different:
Code:
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RT CC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1) ;
port_b_pullups(true);
This is confusing and can lead to errors. Only initialize the hardware one time. Preferably at start of main() or in an init() function.


Code:
if(k=='-') lcd_putc('\f'); lcd_putc(n); while(true);
The 'while(true);' will cause problems as it will wait forever. Looks like a copy/paste error as this line is missing from the end of main().

Code:
#define use_portd_kbd;#endif
Where is the '#if' that belongs to the '#endif'? I assume it is in one of the #include files? This is wrong coding practice. Keep the #if and #endif close together.

Code:
    do
    {
        value100=kbd_getc();
    } while(value100==0);
    lcd_gotoxy(2,1);
    if (value100=='*'
        || value100=='+'
        || value100=='-'
        || value100=='c'
        || value100=='/'
        || value100=='=')
        goto start;
    else
        lcd_putc(value100);
Four times the same sequence... A waste of memory and makes your program harder to read and maintain.
Create a function for this.

Code:
printf(lcd_putc,"\fposition n:%d",n,'\n');
I haven't tried, maybe the CCS compiler accepts it, but standard C wants it as:
Code:
printf(lcd_putc,"\fposition n:%d\n",n);


And I'm sure there are more issues.
wael_007



Joined: 30 May 2010
Posts: 5

View user's profile Send private message

PostPosted: Tue Jun 01, 2010 10:57 am     Reply with quote

Thank you soooo much.
And so sorry if I wasted your time. I'm so happy to be in this forum. Congratulations and good continuation.
I'll try to correct my code and I'll post it.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group