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

why my parameters to function don't work ?

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



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

why my parameters to function don't work ?
PostPosted: Fri Mar 20, 2015 5:31 am     Reply with quote

Hello,

why this don't work:

old_value = 1357;
value = 0;

if(value != old_value){

//split_number(old_value); //digits to global variables g_thous, g_hunds, g_tens and g_ones;
//old_thous = g_thous; old_hunds = g_hunds; old_tens = g_tens; old_ones = g_ones;
//split_number(value); //digits to global variables g_thous, g_hunds, g_tens and g_ones

update_digits(old_value,value,ref_value );
graph_indicator (meter_gain,value,old_value,old_meter_gain);

//calculate distortion percent

}

but this work fine:

void update_digits(int16 old_value, int16 ref_value, int16 value) {

int8 old_thous, old_hunds, old_tens, old_ones;

//old_value = 0; this is ok
//value = 1234; this is ok

split_number(old_value); //digits to global variables g_thous, g_hunds, g_tens and g_ones;
old_thous = g_thous; old_hunds = g_hunds; old_tens = g_tens; old_ones = g_ones;

split_number(value); //digits to global variables g_thous, g_hunds, g_tens and g_ones


if( g_thous != old_thous){

//write old_thous in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(10); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",old_thous);
putc(0x00); //string terminator
com_ok();

//write g_thous in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(10); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",g_thous);
putc(0x00); //string terminator
com_ok();
}

if( g_hunds != old_hunds){

//write old_hunds in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(34); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",old_hunds);
putc(0x00); //string terminator
com_ok();

//write hunds in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(34); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",g_hunds);
putc(0x00); //string terminator
com_ok();
}

if( g_tens != old_tens){

//write old_tens in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(58); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",old_tens);
putc(0x00); //string terminator
com_ok();

//write tens in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(58); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%u",g_tens);
putc(0x00); //string terminator
com_ok();
}

if( g_ones != old_ones){

//write old_ones in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(82); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%u",old_ones);
putc(0x00); //string terminator
com_ok();

//write ones in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(82); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%u",g_ones);
putc(0x00); //string terminator
com_ok();
}

//print 100.0 %

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(10); //top left x LSB
putc(0); //top left y MSB
putc(80); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%s","100.0 %");
putc(0x00); //string terminator
com_ok();

//program stop here:
e:;goto e;

all the variables are int16...
my display show 0000 it should be here 1357

I'm very sure my program really goes to
void update_digits(int16 old_value, int16 ref_value, int16 value)

because I changed that printf("%s","100.0 %");

to 110.0% ...
I'm very confused about this simple problem ...

friendly regards

-arto hautala-
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Mar 20, 2015 6:40 am     Reply with quote

you beat me. i can't tell for the life of me WHAT does not wrok.
ps : learn to use the CODE button
Code:

old_value = 1357;
value = 0;

if(value != old_value){

//split_number(old_value); //digits to global variables g_thous, g_hunds, g_tens and g_ones;
//old_thous = g_thous; old_hunds = g_hunds; old_tens = g_tens; old_ones = g_ones;
//split_number(value); //digits to global variables g_thous, g_hunds, g_tens and g_ones

update_digits(old_value,value,ref_value );
graph_indicator (meter_gain,value,old_value,old_meter_gain);

//calculate distortion percent

}

but this work fine:

void update_digits(int16 old_value, int16 ref_value, int16 value) {

int8 old_thous, old_hunds, old_tens, old_ones;

//old_value = 0; this is ok
//value = 1234; this is ok

split_number(old_value); //digits to global variables g_thous, g_hunds, g_tens and g_ones;
old_thous = g_thous; old_hunds = g_hunds; old_tens = g_tens; old_ones = g_ones;

split_number(value); //digits to global variables g_thous, g_hunds, g_tens and g_ones


if( g_thous != old_thous){

//write old_thous in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(10); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",old_thous);
putc(0x00); //string terminator
com_ok();

//write g_thous in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(10); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",g_thous);
putc(0x00); //string terminator
com_ok();
}

if( g_hunds != old_hunds){

//write old_hunds in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(34); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",old_hunds);
putc(0x00); //string terminator
com_ok();

//write hunds in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(34); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",g_hunds);
putc(0x00); //string terminator
com_ok();
}

if( g_tens != old_tens){

//write old_tens in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(58); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",old_tens);
putc(0x00); //string terminator
com_ok();

//write tens in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(58); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%u",g_tens);
putc(0x00); //string terminator
com_ok();
}

if( g_ones != old_ones){

//write old_ones in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(82); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%u",old_ones);
putc(0x00); //string terminator
com_ok();

//write ones in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(82); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%u",g_ones);
putc(0x00); //string terminator
com_ok();
}

//print 100.0 %

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(10); //top left x LSB
putc(0); //top left y MSB
putc(80); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%s","100.0 %");
putc(0x00); //string terminator
com_ok();
artohautala



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

PostPosted: Fri Mar 20, 2015 6:49 am     Reply with quote

Sorry ,javascript:emoticon('Embarassed')

asmboy

I forgot to use CODE button...

this is also wrong I tried all kind of everything... and I forgot to change it ...

old_value = 1357;
value = 0;

should be :

old_value = 0;
value = 1357;

all the best

-arto-

Embarassed Embarassed
artohautala



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

here is my whole code
PostPosted: Fri Mar 20, 2015 7:23 am     Reply with quote

Code:

/* TÄSSÄ VERSIOSSA OTETAAN KÄYTTÖÖN SÄRÖMITTARI MAHDOLLISUUS ERILLISELLÄ TASOMITTARIN
INPUT BNC-LIITTIMELLÄ
*/

/*/CHECK LIST:

TARKISTA KAIKKI "TESTIT" !

11. tee lopullinen offset hienosäätö lopullisella virtalähteellä, katso word ohje "offset_ohje" !

16. dig arvot muistiin / muistista

18. EI OSAA HAKEA MUISTISTA JOS SÄHKÖT KAUAN POIS PÄÄLTÄ ???????????????????

20. TARKISTA ERI FUNKTIOIDEN EEPROM OSOITEALUE

21. pickit2 tuhoaa eeprommin jos et valitse oikein !
22. jos haluaa hienostella niin vain punaiset tekstit ovat klikattavissa 
23. muuta harmaaksi jos ei klikattavissa MUUTEN PUNAINEN !
24. graph_indicator vähän tyhmästi tekee kaIKELAISTA vaikka tilanne ei ole muuttunut !

*/


#include<18F4525.h>
//reset_cpu();


#device ADC=10                         //10 bits a/d converter
#ORG DEFAULT
#include<stdio.h>
#include <string.h>
#include <stdlib.h>
#use delay(clock=20000000)

#use rs232(FORCE_SW,baud=9600,xmit=pin_c6,rcv=pin_c7,stream=LCD)

#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT

//select D-PORT for extra I/O pins in analog generator, active LOW:
#define ext_d_port     (PIN_C0)           

#define LCD_reset      (PIN_C1)        //reset LCD display module, active LOW
#define rel_20dB       (PIN_C2)        //FUNCTION GENERATOR -20dB attenuator relay
#define pot_cs         (PIN_C3)        //digital potentiometer chip select, active LOW
#define pot_up_down    (PIN_C4)        //digital potentiometer up/down, LOW = DOWN
#define pot_inc        (PIN_C5)        //digital potentiometer incremental

/*C0 extra I/O pin must be low (74244 buffer selected), B5 high (D/A converter chip not selected)
when using D-port pins !*/

#define on_off_rel     (PIN_D0)      //signal on/off relay, 6s delay at startup
#define rel_40dB       (PIN_D1)        //FUNKTION GENERATOR -40dB attenuator relay
#define distm_onoff    (PIN_D2)        //särömittari on-off
#define distm_gain_1   (PIN_D3)        //+20 dB vahvistyspyyntö tasomittarille särömittarilta
#define distm_gain_2   (PIN_D4)        //gain1 + gain2 +40 dB vahv.pyyntö tasomit. särömittarilta
#define att_gain_1     (PIN_D5)        //+20 dB vahvistyspyyntö tasomittarille vaimentimelta
#define att_gain_2     (PIN_D6)        //gain1 + gain2 +40 dB vahv.pyyntö tasomit.vaimentimelta
                                       //PIN_D7 DIGITAL PULSE OUT
                                       
#define level_AD       (PIN_A0)        //level meter A/D input
#define rel_200Hz      (PIN_A1)        //200Hz relay and 200Hz sin. filter
#define rel_2kHz       (PIN_A2)        //2kHz relay and 2kHz sin. filter
#define rel_20kHz      (PIN_A3)        //20kHz relay and 20kHz sin. filter

// (PIN_A4) is for freq: counter input !!

#define rel_20Hz       (PIN_A5)        //20Hz relay and 20 Hz sin. filter
#define triangle_rel   (PIN_E0)        //triangle wave ON state, otherwise sin (XR2206 board)
#define square_rel     (PIN_E1)        //square wave if ON (XR2206 board)
#define sine_rel       (PIN_E2)        //skip sinewave filter when using triangle or square wave

#define DA_wr          (PIN_B4)        //D/A converter write,active LOW
#define DA_cs          (PIN_B5)        //D/A converter chip select,active LOW

#define sine           1               //for sel_wavemode function
#define triangle       2               //for sel_wavemode function
#define square         3               //for sel_wavemode function

#define Hz20           1               //for freq_area function               
#define Hz200          2               //for freq_area function     
#define Hz2k           3               //for freq_area function     
#define Hz20k          4               //for freq_area function     

#define NoTouchActivity           0    //for LCD get touch coordinates   
#define TouchPress                1    //for LCD get touch coordinates   
#define TouchRelease              2    //for LCD get touch coordinates   
#define TouchMoving               3    //for LCD get touch coordinates   
#define GetTouchStatus            4    //for LCD get touch coordinates   
#define GetTouchCoordinates       5    //for LCD get touch coordinates   

#define analog                    1
#define digital                   2
#define distortion                3

#define u_ramp                    6    //these are for digital function select
#define d_ramp                    7
#define up_down                   8
#define pulses                    9
#define bursts                    10
#define BACK                      11

#byte PORTB = 0xF81                   //port A = 0xF80 and so on...
#byte PORTD = 0xF83

void start_init(void);

//color LCD functions:
void com_ok(void);
int8 screen_1(void);
void autobaud(void);
void display_on(void);
void display_off(void);
void backlight_off(void);
void backlight_on(void);
void backlight_colour(int16 bck_colour);         //look color picker !
void draw_button(short int state,int16 x_TOP_LEFT,int16 y_TOP_LEFT,int16 colour,

int8 size,int16 text_colour, char text[]);

void en_touch_screen(void);
void touch_region(int16 x1,int16 x2,int16 y1,int16 y2);
void analog_gen(void);
void wr_range(int8 range);
void wr_divider(int8 divider);
void an_buttons(void);                     //draw analog buttons
void redraw_mode(int8 mode);
void wr_offset(float offset_v);
void sel_wavemode(int8 wave);                        //select sine, triangle or square wave mode
void freq_area(int8 freq_area);                      /*freq. area and corresponding filter selected:
                                                     1...4: 20Hz,200Hz,2kHz and 20 kHz*/
void atten_rel(int8 atten);                          //signal attenuation 0, -20, -40 dB
void relays_off(void);                               //all relays softly OFF
void show_freq_level(int8 wave_mode,int8 divider,int1 show_freq);   

//wave_mode 1 = sine, 2 = triangle 3 = square

void ret_offset_RESET(void);               //returns offset to 0 V after reset or return

void dist_screen(int1 ref_level);          // distortion meter screen
void dist_meter(void);

int8 GetTouch(int8 mode);                  //mode is often 0x04, get touch status page 47 manual
void anadisp_init(int1 show_freq);
void wait_delay(void);
void range_wait(void);
void graph_indicator (int8 meter_gain, int16 value, int16 old_value,int8 old_meter_gain );
void draw_balks(void);
void update_digits(int16 old_value, int16 ref_value, int16 value);

//DIGITAL FUNCTIONS:

int1  digi_gen(void);                   //select digital generator 
int8  ask_waveform(void);               //ask digital function
int1  set_risetime(void);               //set risetime and call run_upramp
void  run_upramp(int16 risetime);       // up ramp is running now 
int1 set_falltime(void);                //set falltime and call run_downramp 
void run_downramp(int16 falltime);      //down ramp is running now
void draw_number(int8 number,int8 x,int8 y);
void clear_ramp_digit(int8 digit);
void show_eememory(int8 wave);
int1 set_rise_falltimes(void);         //set triangle wave rise and falltimes
void run_up_dwnramp(int16 risetime,int16 falltime);      //triangle wave
void split_number(int16 value);
int1 set_dig_pulses(void);
void run_pulses(int16 on_time,int16 off_time,int1 on_us, int1 off_us);      //digital pulses


//global identifiers:

int8 g_ints;
int1 g_high_freq, Gcancel;
static int1 G_START;

static signed int8 g_offset_wiper ;                  //value -127... +128 !

int16 G_xplace,G_yplace;                             //touch coordinates x and y
int8 g_thous, g_hunds, g_tens, g_ones;               // thousands, hundreds, tens and ones

//************************************************************************************************
 void main(void){
 
      int8 mode;
      int1 i;
     
     
     
      delay_ms(1000);
      g_thous = g_hunds = g_tens = g_ones = 0; 
       
        delay_ms(1000);
        g_thous = g_hunds = g_tens = g_ones = 0;
       
       
        G_START = TRUE;
       
        start_init();
        ret_offset_RESET();
       
       
       
       
        i = TRUE;
        while(i){
            mode = screen_1();
     
           if(mode == analog)
            analog_gen();
         
           if(mode == digital)
            digi_gen();
           
           if(mode == distortion)
            dist_meter();
       
        }
 }   

//************************************************************************************************

int1 digi_gen(void){

   int8 waveform;
   
   //DA chip AD7545 is 12 bits LSB D0...D7 MSB B0...B3,
   
   output_high(ext_d_port);     //analog generator use D_port for I/O ! HIGH not sel.
   set_tris_b(0B11110000);      //B-port bits  0...3 outputs 
   set_tris_d(0B00000000);      //D-port all bits outputs     
   output_low(DA_cs);           //select DA-converter
   delay_ms(1);   
   output_low(DA_wr);           // wr to DA-converter
   delay_ms(1);
   
   // first init gard:
   putc(0x40); putc(0x69);com_ok();         
   
   //set to old format (default):
   putc(0x59); putc(0x06);putc(0x00);com_ok();   
   
      waveform = ask_waveform();
     
      if(waveform == FALSE)
      return FALSE;     
     
      if(waveform == u_ramp){
         
         if(set_risetime() == FALSE)
         return FALSE;         
      }
     
      if(waveform == d_ramp){
         
         if( set_falltime()== FALSE)
         return FALSE;         
      }
     
      if(waveform == up_down){
         
         if(set_rise_falltimes() == FALSE)
         return FALSE;         
      }     
   
      if(waveform == pulses){
         
         if(set_dig_pulses() == FALSE)
         return FALSE;         
      }         
   
   }

//************************************************************************************************

   //this loads up going ramp from memory picture from sd-card:

      void ur1(void){

      /*Picaso Data:
      0x40, 0x6D, "func_gen.Gci", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x7E, 0x00     
      */     
         putc(0x40);putc(0x6D);
         printf ("func_gen.Gci");
         putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);
         putc(0x3F);putc(0x7E);putc(0x00);
         com_ok();           

}

//************************************************************************************************

   //this loads up going ramp INFORMATION picture from sd-card:

void ur2(void){

      /*Picaso Data:
      0x40, 0x6D, "func_gen.Gci", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0xD8, 0x00     
      */     
         putc(0x40);putc(0x6D);
         printf ("func_gen.Gci");
         putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);
         putc(0x41);putc(0xD8);putc(0x00);
         com_ok();           

}

//************************************************************************************************

void ur3(void){

   //this loads set up rise time of up going ramp picture from sd-card:

      /*Picaso Data:
      0x40, 0x6D, "func_gen.Gci", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x32, 0x00     
      */     
         putc(0x40);putc(0x6D);
         printf ("func_gen.Gci");
         putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);
         putc(0x44);putc(0x32);putc (0x00);
         com_ok();           
}

//************************************************************************************************

void ur4(void){

   //this loads save rise time of up going ramp picture from sd-card:

      /*Picaso Data:
      0x40, 0x6D, "func_gen.Gci", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8C, 0x00     
      */     
         putc(0x40);putc(0x6D);
         printf ("func_gen.Gci");
         putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);
         putc(0x46);putc(0x8C);putc (0x00);
         com_ok();           
}



//************************************************************************************************

      //this loads down going ramp from memory picture from sd-card:

void dr5(void){

      /*Picaso Data:
      0x40, 0x6D, "func_gen.Gci", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x7E, 0x00     
      */     
         putc(0x40);putc(0x6D);
         printf ("func_gen.Gci");
         putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);
         putc(0x17);putc(0x84);putc(0x00);
         com_ok();           

}

//************************************************************************************************

      //this loads down going information picture from sd-card:

void dr6(void){

      /*Picaso Data:
      0x40, 0x6D, "func_gen.Gci", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0xDE, 0x00     
      */     
         putc(0x40);putc(0x6D);
         printf ("func_gen.Gci");
         putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);
         putc(0x19);putc(0xDE);putc(0x00);
         com_ok();           

}
//************************************************************************************************

      //this loads down going ramp from memory picture from sd-card:

void dr7(void){

      /*Picaso Data:
      0x40, 0x6D, "func_gen.Gci", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x7E, 0x00     
      */     
         putc(0x40);putc(0x6D);
         printf ("func_gen.Gci");
         putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);
         putc(0x1C);putc(0x38);putc(0x00);
         com_ok();           

}

//************************************************************************************************

      //this loads to memory down going ramp picture from sd-card:

void dr8(void){

      /*Picaso Data:
      0x40, 0x6D, "func_gen.Gci", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x92, 0x00     
      */     
         putc(0x40);putc(0x6D);
         printf ("func_gen.Gci");
         putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);
         putc(0x1E);putc(0x92);putc(0x00);
         com_ok();           

}

//************************************************************************************************

      //this loads  triangle picture from sd-card:

void tr9(void){

      /*Picaso Data:
      0x40, 0x6D, "func_gen.Gci", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x16, 0x00     
      */     
         putc(0x40);putc(0x6D);
         printf ("func_gen.Gci");
         putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);
         putc(0x36);putc(0x16);putc(0x00);
         com_ok();           

}

//************************************************************************************************

      //this loads  triangle INFORMATION picture from sd-card:

void tr10(void){

      /*Picaso Data:
      0x40, 0x6D, "func_gen.Gci", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x70, 0x00     
      */     
         putc(0x40);putc(0x6D);
         printf ("func_gen.Gci");
         putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);
         putc(0x38);putc(0x70);putc(0x00);
         com_ok();           

}


//************************************************************************************************

      //this loads  triangle picture risetime / falltime from sd-card:

void tr11(void){

      /*Picaso Data:
      0x40, 0x6D, "func_gen.Gci", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3A, 0xCA, 0x00     
      */     
         putc(0x40);putc(0x6D);
         printf ("func_gen.Gci");
         putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);
         putc(0x3A);putc(0xCA);putc(0x00);
         com_ok();           

}


//************************************************************************************************

      //this loads  pulses INFORMATION picture from sd-card:

void pu14(void){

      /*Picaso Data:
        0x40, 0x6D, "func_gen.Gci", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0xA0, 0x00
      */
         putc(0x40);putc(0x6D);
         printf ("func_gen.Gci");
         putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);
         putc(0x25);putc(0xA0);putc(0x00);
         com_ok();           
}

//************************************************************************************************
      //this loads  pulses new value picture from sd-card:

void pu15(void){

      /*Picaso Data:
        0x40, 0x6D, "func_gen.Gci", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x27, 0xFA, 0x00     
      */
         putc(0x40);putc(0x6D);
         printf ("func_gen.Gci");
         putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);
         putc(0x27);putc(0xFA);putc(0x00);
         com_ok();           
}


//************************************************************************************************
int8 ask_waveform(void){

   /*/first load screen from SD-card that ask waveform:
   the data below is from SGS graphics controller:*/
 
   /*Picaso Data:
   0x40, 0x6D, "func_gen.Gci", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0xBC, 0x00
   */

   putc(0x40);putc(0x6D);
   printf ("func_gen.Gci");
   putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);
   putc(0x33);putc(0xBC);putc(0x00);
   com_ok();     
 
      //destroy burst it is not used
     
      putc(0x72);putc(0); putc(110);putc(0);putc(154);putc(0); putc(210);putc(0); putc(224);
      putc(0xAE);putc(0xDC);       
      com_ok();     
   
   
   
   /*   up_ramp  button  x1 = 6,   x2 = 105,  y1 =  80,  y2 = 150
        d_ramp   button  x1 = 110, x2 = 210,  y1 =  80,  y2 = 150
        triangle button  x1 = 215, x2 = 314,  y1 =  80,  y2 = 150 
        pulses   button  x1 = 6,   x2 = 105,  y1 = 155,  y2 = 224
        bursts   button  x1 = 110, x2 = 210,  y1 = 155,  y2 = 224
        BACK     button  x1 = 215, x2 = 314,  y1 = 155,  y2 = 224   
   */
     
      en_touch_screen();
      touch_region(0,319,0,239);         //detect touch region, whole display

           
         
      while(TRUE){
           
            //wait until touch press forever
            do{
            ;
            }while(GetTouch(GetTouchStatus) != Touchpress);
           
            GetTouch(GetTouchCoordinates);      //coordinates for buttons
           
           //up going ramp button pressed:
           if((G_xplace > 6) && (G_xplace < 105) && (G_yplace > 80) && (G_yplace < 150)){
           putc(0x45); com_ok();           //clear screen           
           return u_ramp;
           }
           
           //down going ramp button pressed:
           if((G_xplace > 110) && (G_xplace < 210) && (G_yplace > 80) && (G_yplace < 150)){
           putc(0x45); com_ok();           //clear screen           
           return d_ramp;
           }

           //triangle wave button pressed:
           if((G_xplace > 215) && (G_xplace < 314) && (G_yplace > 80) && (G_yplace < 150)){
           putc(0x45); com_ok();           //clear screen           
           return up_down;
           }

           //pulses button pressed:
           if((G_xplace >6) && (G_xplace < 105) && (G_yplace > 155) && (G_yplace < 224)){
           putc(0x45); com_ok();           //clear screen           
           return pulses;
           }
           
           //Gcancel button pressed:
           if((G_xplace >215) && (G_xplace < 314) && (G_yplace > 155) && (G_yplace < 224)){
           putc(0x45); com_ok();           //clear screen           
           return FALSE;
           }   
      }

}

//************************************************************************************************
int8 GetTouch(int8 mode){     /*mode = 4 or 5, get touch status or get touch coordinates,
                                page 47 manual*/
         
         int8 x_coord_MSB,x_coord_LSB,y_coord_MSB,y_coord_LSB;
         
         if(mode == GetTouchStatus){
         
           putc(0x6F);                   //cmd, get touch cordinates
           putc(GetTouchStatus);                 
         
           while(!kbhit(LCD))
           delay_us(1);
         
           x_coord_MSB = getc(LCD);    //read characters from UART
           x_coord_LSB = getc(LCD);     
           y_coord_MSB = getc(LCD);               
           y_coord_LSB = getc(LCD);           

           return x_coord_LSB;         //status data is in x_coord_LSB
         }
         
         if(mode == GetTouchCoordinates){
         
           putc(0x6F);                   //cmd, get touch cordinates
           putc(GetTouchCoordinates);                 
         
           while(!kbhit(LCD))
           delay_us(1);
         
           x_coord_MSB = getc(LCD);    //read characters from UART
           x_coord_LSB = getc(LCD);     
           y_coord_MSB = getc(LCD);               
           y_coord_LSB = getc(LCD);           
           
           G_xplace = make16( x_coord_MSB,x_coord_LSB); //make globals G_xplace && G_yplace
           G_yplace = make16( y_coord_MSB,y_coord_LSB);
           return mode;                                //returns 5 and set G_xplace && G_yplace           
         }
 
}
//************************************************************************************************
void show_freq_level(int8 wave_mode,int8 divider,int1 show_freq){ 
         
         /* wave_mode 1 = sine, 2 = triangle 3 = square
           
            to measure frequence put pulses from XR2206 pin 11 to A4 pin and use timer_0
            and use FET BS170 as level converter to +1..+3 to 0...+5 V level
         */
         
         int32 freq;
         static int32 old_freq;
         int32 old_value;   
         int32 value;
         static unsigned int old_thous, old_hunds, old_tens, old_ones;
         
//fREQUENCE ...............................................................................         
     
      if( show_freq == TRUE){
     
         set_timer0(0);
         setup_timer_0(RTCC_EXT_L_TO_H);         
         
         //use timer(1) interrupt for 1 s gate time:
          set_timer1(1);
         
          SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_8); 
          enable_interrupts(INT_TIMER1);
          enable_interrupts(GLOBAL);                                                   
         
          //pulses to A4 pin and use timer_0 (same to RTTC)
          setup_timer_0(RTCC_EXT_L_TO_H);                   
          SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_8);  //overflow interrupt every 104.858ms if div 8
          enable_interrupts(INT_TIMER1);
          enable_interrupts(GLOBAL);           
          set_timer0(0);

          //high_freq is global,it is set or reset in analog_gen() 
         
          if(g_high_freq == FALSE){                   //freq. 20 ... 20000 Hz
         
          set_timer1(60400);
          g_ints = 0;
          set_timer0(0);
          while(g_ints < 20);                        //wait for gate time 1s , res. 1 Hz
          freq = get_timer0();
          }
         
          if(g_high_freq == TRUE){                    //freq. 20000 ... 200000 Hz
         
          set_timer1(6050);                        //this number is experiantal!
          g_ints = 0;
          set_timer0(0);
          while(g_ints < 2);                       //wait for gate time 0.1 s , res. = 10 Hz
          freq = get_timer0();
          freq = freq * 10;
          }
         
          disable_interrupts(INT_TIMER1);
          disable_interrupts(GLOBAL);           
         
          //show frequence:
          putc(0x73);                    //cmd write text string
          putc(16);                      //column in character units
          putc(3);                       //row in character units
          putc(0x03);                    //font 8 x 12         
          putc(0xF8);                    //string colour red
          putc(0x00);       
          printf("%06Lu",freq);
          putc(0x00);                     //string terminator
          com_ok();
         
          //show frequence only if frequence has changed:
         
         
           if(old_freq != freq){
         
          //clear old frequence: 
          putc(0x73);                    //cmd write text string
          putc(16);                      //column in character units
          putc(3);                       //row in character units
          putc(0x03);                    //font 8 x 12         
          putc(0xFF);                    //string colour  white
          putc(0xFF);
          printf("%06Lu",old_freq);
          putc(0x00);                     //string terminator
          com_ok();                   
         
          //then write new frequence:
          putc(0x73);                    //cmd write text string
          putc(16);                      //column in character units
          putc(3);                       //row in character units
          putc(0x03);                    //font 8 x 12         
          putc(0xF8);                    //string colour red
          putc(0x00);       
          printf("%06Lu",freq);
          putc(0x00);                     //string terminator
          com_ok();
          old_freq = freq;
          }
      }

// LEVEL ......................................................................................
         
         /*measure signal level, pin A0 is A/D converter input and signal is rectified...
          with external circuit board ... so A/D measures DC voltage
          sine wave  4 Vpp is number 558 from A/D
          ( TESTIT trimmaa lopullisella powerilla)         
          so 4 Vpp is 4000 mVpp...number 558 equals number 4000 so multiplier is number 7.1685
          (resolution here is about 8 mV)
          first multiplier value = value * 7168, then divide result with 1000*/
         
          setup_adc_ports(AN0_ANALOG );                 // pin A0 measures voltage level
          setup_adc( ADC_CLOCK_INTERNAL );         
          delay_ms(2);
          value = read_adc();           //A/D conversion
          delay_ms(20);                 //OK delay for AD conversion testit
         
            value = (value * 7168) /1000;      //peak to peak value sine wave*/
            value = value / 10;                //rounding value because resolution is 10 bits   
            value = value * 10;         
         
         switch(wave_mode)
         {
            case sine:                         //default OK for sinewave
            ;
            break;
   
            case triangle:                             
            value = value * 125;
            value = value / 100;
            break;
           
            case square:                               
            value = value * 65;
            value = value / 100;
            break;
         }
         
         switch(divider)
         {
            case 0:                             
            output_low(att_gain_1),           //+20 dB gain relay off
            output_low(att_gain_2),           //+20 dB gain relay off
            value = value;                    //no attenuation, no gain
            break;
   
            case 1:                            //-20dB attenuation 
            output_high(att_gain_1),           //+20 dB gain relay on
            value = value / 10;
            break;
           
            case 2:                            //-40dB attenuation                             
            output_high(att_gain_1),           //+20 dB gain relay on
            output_high(att_gain_2),           //+20 dB gain relay on
            value = value / 100;
            break;
         }         
         
          //show new level digits only if they are changed:
         
          delay_ms(50); //???????????????????? ei kai trvita
   
         
         /*
         //update value:
         if(value != old_value){     
          putc(0x73);                    //cmd write text string
          putc(16);                      //column in character units
          putc(5);                       //row in character units
          putc(0x03);                    //font 8 x 12         
          putc(0xFF);                    //string colour white
          putc(0xFF);       
          printf("%04Lu",value);
          putc(0x00);                     //string terminator
          com_ok();         
          */
         
          putc(0x73);                    //cmd write text string
          putc(16);                      //column in character units
          putc(5);                       //row in character units
          putc(0x03);                    //font 8 x 12         
          putc(0x00);                    //string colour black
          putc(0x00);       
          printf("%04Lu",value);
          putc(0x00);                     //string terminator
          com_ok();
           
   
   
   
    if(value != old_value){
         
        split_number(old_value);  //digits to global variables g_thous, g_hunds, g_tens and g_ones;       
        old_thous = g_thous; old_hunds = g_hunds; old_tens = g_tens; old_ones = g_ones; 
        split_number(value);  //digits to global variables g_thous, g_hunds, g_tens and g_ones       
       
       
       
       
       
       
       
       
       
        /*
        old_thous = g_thous;
        old_hunds = g_hunds;
        old_tens  = g_tens;
        old_ones  = g_ones;
        */
       
        //split_number(value);  //digits to global variables g_thous, g_hunds, g_tens and g_ones;
         
        if((g_thous != old_thous)){   
               
                   //clear digit thousands, write old_thousands white:
                   
                   putc(0x73);                    //cmd write text string
                   putc(16);                      //column in character units
                   putc(5);                       //row in character units
                   putc(0x03);                    //font 8 x 12         
                   putc(0xFF);                    //string colour  white
                   putc(0xFF);
                   printf("%u",old_thous);
                   putc(0x00);                     //string terminator
                   com_ok();
                   
                   //print new digit thousands:
                   
                   putc(0x73);                    //cmd write text string
                   putc(16);                      //column in character units
                   putc(5);                       //row in character units
                   putc(0x03);                    //font 8 x 12         
                   putc(0x00);                    //string colour  black
                   putc(0x00);
                   printf("%u",g_thous);
                   putc(0x00);                     //string terminator
                   com_ok();
        }           
                   
        if((g_hunds != old_hunds)){   
               
                   //clear digit hundreds, write old_hundreds white:
                   
                   putc(0x73);                    //cmd write text string
                   putc(17);                      //column in character units
                   putc(5);                       //row in character units
                   putc(0x03);                    //font 8 x 12         
                   putc(0xFF);                    //string colour  white
                   putc(0xFF);
                   printf("%u",old_hunds);
                   putc(0x00);                     //string terminator
                   com_ok();
                   
                   //print new digit hunds:
                   
                   putc(0x73);                    //cmd write text string
                   putc(17);                      //column in character units
                   putc(5);                       //row in character units
                   putc(0x03);                    //font 8 x 12         
                   putc(0x00);                    //string colour  black
                   putc(0x00);
                   printf("%u",g_hunds);
                   putc(0x00);                     //string terminator
                   com_ok();
                   
        }                   
                   
        if((g_tens != old_tens)){   
               
                   //clear digit hundreds, write old_hundreds white:
                   
                   putc(0x73);                    //cmd write text string
                   putc(18);                      //column in character units
                   putc(5);                       //row in character units
                   putc(0x03);                    //font 8 x 12         
                   putc(0xFF);                    //string colour  white
                   putc(0xFF);
                   printf("%u",old_tens);
                   putc(0x00);                     //string terminator
                   com_ok();
                   
                   //print new digit hunds:
                   
                   putc(0x73);                    //cmd write text string
                   putc(18);                      //column in character units
                   putc(5);                       //row in character units
                   putc(0x03);                    //font 8 x 12         
                   putc(0x00);                    //string colour  black
                   putc(0x00);
                   printf("%u",g_tens);
                   putc(0x00);                     //string terminator
                   com_ok();
        }                         
                 
   
       
        if((g_ones != old_ones)){
               
                   //clear digit hundreds, write old_hundreds white:
                   
                   putc(0x73);                    //cmd write text string
                   putc(19);                      //column in character units
                   putc(5);                       //row in character units
                   putc(0x03);                    //font 8 x 12         
                   putc(0xFF);                    //string colour  white
                   putc(0xFF);
                   printf("%u",old_ones);
                   putc(0x00);                     //string terminator
                   com_ok();
                   
                   //print new digit hunds:
                   
                   putc(0x73);                    //cmd write text string
                   putc(19);                      //column in character units
                   putc(5);                       //row in character units
                   putc(0x03);                    //font 8 x 12         
                   putc(0x00);                    //string colour  black
                   putc(0x00);
                   printf("%u",g_ones);
                   putc(0x00);                     //string terminator
                   com_ok();
        }
   
                   old_value = value;                   
    }

}

//************************************************************************************************

void analog_gen(void){
       
        int1 show_freq,run;
        int8 onoff_mode,oldonoff_mode, range,divider,mode,loop,wave_mode,pot_delay;
        int16 delay;
       
        float f_offset = 0 ;
         
        pot_delay = 1;
       
        ret_offset_RESET();         //returns 0 V offset voltage after RETURN or RESET     
       
        //ret_offset();                  //returns 0 V offset voltage after RETURN
         
         //first these settings:
         output_high(rel_20Hz);     delay_ms(5);  //A5, 20Hz relay and 20Hz sine filter ON
         pot_delay = 5;
         
         //g_offset_wiper = 0;
         
         delay_ms(100);
         onoff_mode = 5;                  //first no output, button reads "RUN"
         output_high(DA_cs);              //D/A converter not selected
         delay_ms(1);
         output_low(ext_d_port);          //ext d-port selected
         delay_ms(1);         
         output_low(on_off_rel);          //D0, signal on/off relay off
         delay_ms(20);         
         
         freq_area(Hz200);               //20...200 relay ON
         divider = 0;                    //no attenuation 0dB
         atten_rel(divider);
         
         sel_wavemode(sine);             //sinewave relay ON
         
         G_xplace = G_yplace = 0;
         
         an_buttons();            //draw analog buttons
         
         /*write default values: range = 1(20...200Hz),mode = 1 (sinewave), divider = 1 (1/1)
         offset = 0 V */
         
         mode = 0;
         range =1;
         wr_range(range);               //frequence range default value =1 = 20-200Hz
         freq_area(range);               //frequence relay ON first 20...200Hz area
         g_high_freq = FALSE;
         wr_divider(0);
         
         //offset_V 0V...+-2.2V
         
         //ret_offset();                  //returns 0 V offset voltage after RETURN or RESET
         
         
         wr_offset(f_offset);             //default value 0.00 V
         f_offset = 0;
         
         en_touch_screen();
         touch_region(0,319,0,239);         //detect touch region, whole display
         delay_ms(100);
       
          wave_mode = sine;       
          show_freq = FALSE;
         
          anadisp_init(show_freq);       
       
        do{                                    //DO until RETURN pressed
           
           mode = GetTouch(GetTouchStatus);
           
           do{
           mode = GetTouch(GetTouchStatus);
           show_freq_level(wave_mode,divider, show_freq);//measure and show freq. && signal level
           }while(mode != TouchPress);                 //wait touch press

/*
#define NoTouchActivity           0    //for LCD get touch coordinates
#define TouchPress                1    //for LCD get touch coordinates   
#define TouchRelease              2    //for LCD get touch coordinates   
#define TouchMoving               3    //for LCD get touch coordinates   
#define GetTouchStatus            4    //for LCD get touch coordinates   
#define GetTouchCoordinates       5    //for LCD get touch coordinates   
*/           
           
            GetTouch(GetTouchCoordinates);
           
            //show freq button pressed:
           
            if((G_xplace > 190) && (G_xplace < 310) && (G_yplace > 44) && (G_yplace < 64)){
           
               if(show_freq == FALSE)
               show_freq = TRUE;
               
               else
               show_freq = FALSE;           
           
               anadisp_init(show_freq);
           
            }           
           
            //(G_xplace && G_yplace are global identifiers)
           
            //freq.range button pressed:
         
  if((G_xplace > 9) && (G_xplace < 171) && (G_yplace > 9) && (G_yplace < 35)&& (run == FALSE)){
           
           
            do{
              ++range;
              if(range == 5)                     //freq.range 1...4
              range = 1;
             
              if(range < 4)
              g_high_freq = FALSE;              //1s gate time to number 16 bits 65535 Hz
             
              if(range == 4)                    //0.1s gate time to number 200000 Hz max. 
              g_high_freq = TRUE;
             
              wr_range(range);                //write freq.area to display
             
              freq_area(range);               //frequence relay ON
             
             
              delay_ms(500);
             
              mode = GetTouch(GetTouchStatus);
             
             }while(mode != TouchRelease);                  //wait touch release   
           
  }
           
            //divider button pressed:
           
            if((G_xplace > 9) && (G_xplace < 171) && (G_yplace > 131) && (G_yplace < 155)){
             
             do{
             
             if(divider < 4)                     //divider 0dB = 0, -20 = 1 and -40 dB = 2
             ++divider;
             if(divider == 3)                   
             divider = 0;
             wr_divider(divider);
             atten_rel(divider);             
             delay_ms(500);
             mode = GetTouch(GetTouchStatus);
             }while(mode != TouchRelease);                  //wait touch release
            }
           
   //sinewave button pressed:
   
   if((G_xplace > 9) && (G_xplace < 171) && (G_yplace > 39) && (G_yplace < 65)&& (run == FALSE)){
             
             sel_wavemode(sine);
             redraw_mode(1);      // sine button
             show_freq = FALSE;
             anadisp_init(show_freq);       
             mode = 0;
             range =1;
             wr_range(range);               //frequence range default value =1 = 20-200Hz
             freq_area(range);               //frequence relay ON first 20...200Hz area
             g_high_freq = FALSE;
             
         
             //offset_V 0V...+-2.2V
         
             //offset = 0;
             wr_offset(f_offset);                  //default value 0.00 V
             
             if(onoff_mode == 5)              //mode OFF, button reads RUN
               redraw_mode(4);             
             
             if(onoff_mode == 4){              //mode ON, button reads OFF
               redraw_mode(5);
               output_high(on_off_rel);          //output relay ON 
             }
             
             sel_wavemode(sine);            //sinewave relay ON
             wave_mode = sine;
             //show_freq_level(sine);          //measure and show freq. && signal level
             
             do{
                mode = GetTouch(GetTouchStatus);
              }while(mode != TouchRelease);                  //wait touch release                     
   }
           
      //triangle button pressed:
   if((G_xplace > 9) && (G_xplace < 171) && (G_yplace > 69) && (G_yplace < 95) && (run == FALSE)){
           
             delay_ms(20);
             output_low(on_off_rel);          //D0, signal on/off relay off
             delay_ms(20);         
             redraw_mode(4);
             
             //mode = 2;                     //mode triangle wave
             redraw_mode(triangle);
             sel_wavemode(triangle);            //sinewave relay ON
             wave_mode = triangle;           
             
             do{
             mode = GetTouch(GetTouchStatus);
             }while(mode != TouchRelease);                  //wait touch release         
   }
         
   //square button pressed:
   if((G_xplace > 9) && (G_xplace < 171) && (G_yplace > 99) && (G_yplace < 125)&& (run == FALSE)) {
           
             delay_ms(20);
             output_low(on_off_rel);          //D0, signal on/off relay off
             delay_ms(20);         
             redraw_mode(4);
             
             //mode = 3;                     //mode square wave
             redraw_mode(square);
             sel_wavemode(square);         //square relay ON     
             //show_freq_level(square);          //measure and show freq. && signal level
             
              wave_mode = square;
             
             do{
              mode = GetTouch(GetTouchStatus);
             }while(mode != TouchRelease);                  //wait touch release         
   }
             
         //+ offset button pressed:

         if ((G_xplace > 121) && (G_xplace < 139) && (G_yplace > 159) && (G_yplace < 185)){
           
            delay = 500; loop = 0;
           
            do{
             
              //f_offset = f_offset + 0.04;
             
              f_offset = f_offset + 0.04;             
             
              wr_offset(f_offset);
              --g_offset_wiper; 
           
               delay_ms(delay);
           
               if(loop > 5) delay = 1;
           
               //set offset towards positive voltage:
               output_high(pot_cs);                    //dig. pot not selected
               delay_ms(pot_delay);
               output_low(pot_up_down);                //dig.pot wiper LOW, makes offset V higher!
               delay_ms(pot_delay);                       
               output_high(pot_inc);                   
               delay_ms(pot_delay);                     
           
               output_low(pot_cs);                     //dig. pot selected
               delay_ms(pot_delay);                         
               
               //output_high(pot_inc);                    //pulse dig. pot, store
               
               output_low(pot_inc);                    //pulse dig. pot, no store
               
               delay_ms(pot_delay);
               output_high(pot_cs);                   
               delay_ms(pot_delay);               
               
               G_xplace = G_yplace = 0;
           
               ++loop;
               
               mode = GetTouch(GetTouchStatus);
           
            }while ((mode != TouchRelease) && (f_offset < 2));       //wait touch release   
               
          }
           
            //- offset button pressed:
           
            if((G_xplace > 153) && (G_xplace < 169) && (G_yplace > 159) && (G_yplace < 185)){
           
            delay = 500; loop = 0;
           
            do{
              f_offset = f_offset - 0.04;
              wr_offset(f_offset);           
              ++g_offset_wiper; 
             
            delay_ms(delay);
           
            if(loop > 5)
            delay = 1;
           
           
               //set offset towards negative voltage:
               output_high(pot_cs);                    //dig. pot not selected
               delay_ms(pot_delay);
               output_high(pot_up_down);                //dig.pot wiper HIGH, makes offset V [spam]!
               delay_ms(pot_delay);                       
               output_high(pot_inc);                   
               delay_ms(pot_delay);                     
           
               output_low(pot_cs);                     //dig. pot selected
               delay_ms(pot_delay);                         
               output_low(pot_inc);                    //pulse dig. pot, no store
               delay_ms(pot_delay);                       
               output_high(pot_cs);                   
               delay_ms(pot_delay);                         
           
             ++loop;
             mode = GetTouch(GetTouchStatus);           
           
            }while ((mode != TouchRelease) && (f_offset > -2));       //wait touch release 
          }
           
            //RUN button pressed:
            //if((G_xplace > 9) && (G_xplace < 118) && (G_yplace > 199) && (G_yplace < 230)){
            if((G_xplace > 9) && (G_xplace < 94) && (G_yplace > 199) && (G_yplace < 230)){
           
           
             if(onoff_mode == 5){        //mode to ON, button reads OFF AFTER PRESS!
             
             run = TRUE;
             wait_delay();               //wait generator to setup few seconds
             output_high(on_off_rel);    //D0, signal on/off relay to ON
             delay_ms(5);         
             redraw_mode(5);
             oldonoff_mode = 5;
             }
             
             if(onoff_mode == 4){              //mode to off, button reads RUN AFTER PRESS!
             
             run = FALSE;
             output_low(on_off_rel);          //D0, signal on/off relay off
             delay_ms(5);         
             redraw_mode(4);
             oldonoff_mode = 4;
             }
             
             if(oldonoff_mode == 4){            //mode ON, button reads OFF
             onoff_mode = 5;
             }
             
             if(oldonoff_mode == 5){            //mode OFF, button reads RUN
             onoff_mode = 4;
             }
           
            do{
            mode = GetTouch(GetTouchStatus);
            }while(mode != TouchRelease);                  //wait touch release   
            delay_ms(20);
           
            }
           
 
      //DIST button pressed:
      if((G_xplace > 203) && (G_xplace < 298) && (G_yplace > 201) && (G_yplace < 236)) {
 
          dist_meter();
         
         
         
// OK digi_gen();
 
 
 
 
         do{
            mode = GetTouch(GetTouchStatus);
           }while(mode != TouchRelease);                  //wait touch rele
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Mar 20, 2015 10:56 am     Reply with quote

Like asmboy says, you need to tell us:-

1) What your code is intended to do.
2) What works.
3) What it's actually doing wrong.

It would also be useful if you could reduce your post to a SHORT, COMPLETE, COMPILABLE code which shows the problem.
(Say 15 lines MAX.)

Most of the guys here (the ones who could help) are not prepared to wade through several page full of irrelevant material.

Mike
artohautala



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

PostPosted: Fri Mar 20, 2015 11:24 am     Reply with quote

Mike Walne wrote:
Like asmboy says, you need to tell us:-

1) What your code is intended to do.
2) What works.
3) What it's actually doing wrong.

It would also be useful if you could reduce your post to a SHORT, COMPLETE, COMPILABLE code which shows the problem.
(Say 15 lines MAX.)

Most of the guys here (the ones who could help) are not prepared to wade through several page full of irrelevant material.

Mike


Hello Mike,

and lot of thanks you answering me ...

the main problem is shortly here :

why I can't send parameters to my function

update_digits(int16 old_value, int16 ref_value, int16 value)

why this don't work:

old_value = 0;
value = 1357;

if(value != old_value){

update_digits(int16 old_value, int16 ref_value, int16 value)

}

but this work fine:

void update_digits(int16 old_value, int16 ref_value, int16 value) {

int8 old_thous, old_hunds, old_tens, old_ones;

//old_value = 0; this is ok
//value = 1234; this is ok

split_number(old_value); //digits to global variables g_thous, g_hunds, g_tens and g_ones;
old_thous = g_thous; old_hunds = g_hunds; old_tens = g_tens; old_ones = g_ones;

split_number(value); //digits to global variables g_thous, g_hunds, g_tens and g_ones


if( g_thous != old_thous){

//write old_thous in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(10); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",old_thous);
putc(0x00); //string terminator
com_ok();

//write g_thous in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(10); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",g_thous);
putc(0x00); //string terminator
com_ok();
}

if( g_hunds != old_hunds){

//write old_hunds in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(34); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",old_hunds);
putc(0x00); //string terminator
com_ok();

//write hunds in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(34); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",g_hunds);
putc(0x00); //string terminator
com_ok();
}

if( g_tens != old_tens){

//write old_tens in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(58); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",old_tens);
putc(0x00); //string terminator
com_ok();

//write tens in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(58); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%u",g_tens);
putc(0x00); //string terminator
com_ok();
}

if( g_ones != old_ones){

//write old_ones in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(82); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%u",old_ones);
putc(0x00); //string terminator
com_ok();

//write ones in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(82); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%u",g_ones);
putc(0x00); //string terminator
com_ok();
}

//print 100.0 %

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(10); //top left x LSB
putc(0); //top left y MSB
putc(80); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%s","100.0 %");
putc(0x00); //string terminator
com_ok();

//program stop here:
e:;goto e;

old_value = 1357;
value = 0;

if(value != old_value){

//split_number(old_value); //digits to global variables g_thous, g_hunds, g_tens and g_ones;
//old_thous = g_thous; old_hunds = g_hunds; old_tens = g_tens; old_ones = g_ones;
//split_number(value); //digits to global variables g_thous, g_hunds, g_tens and g_ones

update_digits(old_value,value,ref_value );
graph_indicator (meter_gain,value,old_value,old_meter_gain);

//calculate distortion percent

}

but this work fine:

void update_digits(int16 old_value, int16 ref_value, int16 value) {

int8 old_thous, old_hunds, old_tens, old_ones;

//old_value = 0; this is ok
//value = 1234; this is ok

split_number(old_value); //digits to global variables g_thous, g_hunds, g_tens and g_ones;
old_thous = g_thous; old_hunds = g_hunds; old_tens = g_tens; old_ones = g_ones;

split_number(value); //digits to global variables g_thous, g_hunds, g_tens and g_ones


if( g_thous != old_thous){

//write old_thous in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(10); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",old_thous);
putc(0x00); //string terminator
com_ok();

//write g_thous in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(10); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",g_thous);
putc(0x00); //string terminator
com_ok();
}

if( g_hunds != old_hunds){

//write old_hunds in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(34); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",old_hunds);
putc(0x00); //string terminator
com_ok();

//write hunds in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(34); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",g_hunds);
putc(0x00); //string terminator
com_ok();
}

if( g_tens != old_tens){

//write old_tens in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(58); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 2
putc(0x02); //height multiplier = 2
printf("%u",old_tens);
putc(0x00); //string terminator
com_ok();

//write tens in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(58); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%u",g_tens);
putc(0x00); //string terminator
com_ok();
}

if( g_ones != old_ones){

//write old_ones in backround colour to clean it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(82); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0xC6); //string colour backcolour
putc(0x18); //string colour backcolour
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%u",old_ones);
putc(0x00); //string terminator
com_ok();

//write ones in black colour to show it

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(82); //top left x LSB
putc(0); //top left y MSB
putc(120); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%u",g_ones);
putc(0x00); //string terminator
com_ok();
}

//print 100.0 %

putc(0x53); //cmd write ASCII text string graphics format, page 44
putc(0); //top left x MSB
putc(10); //top left x LSB
putc(0); //top left y MSB
putc(80); //top left y LSB
putc(3); //font 3 = 12 x 16
putc(0x00); //string colour black
putc(0x00); //string colour black
putc(0x02); //widht multiplier = 3
putc(0x02); //height multiplier = 3
printf("%s","100.0 %");
putc(0x00); //string terminator
com_ok();

//program stop here:
e:;goto e;
Code:


Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Mar 20, 2015 12:07 pm     Reply with quote

You're still not getting it.

Please:-
a) Use the code button.
b) Reduce your code to about 15 lines MAX.
c) Read the forum guidelines.

I (and many others) will not wade through pages of code.
You're the one wanting help, we've got better things to do.
Make it easier for us to help you.

Mike
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