Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Function addition between function.

Status
Not open for further replies.

koolguy

Active Member
Hello,
How to add function between this calling function...
display(" Led ");
unsigned char a=5; which will change reliquary
how to add a variable between " suppose a"
display(" a");

thanks
 
Hello,
It says Convert integer to string (non-standard function)
but here we need to get the data store in variable..

r=get(char av);
display(a);
blit(1);


example a is holding counter temperature reading!
 
Hello,
i you remember there was code on scrolling :

So, i want to add here the variable things doing it with itoa will do this easily ?
can't we do these function directly insert to display(" ") function, so, if we want to add serial update like wifi bluetoth?
display(char *str)
{

int addr;
int z;
while(*str!=0){
addr = ((int)*str++ - 0x20);
addr *= 5;
int y=0;
for(z=0;z<5;z++){
leds[z] = Font2[addr+y];
y++;
}


clear();
display(" Led ");
blit(1);
 
OK, for suppose there is counter up/down from switch pres!
How, to represent it in itoa?
as here we simply text constant display(" text ");
but in this case how to display store number in memory?
 
Add 1 more line to Ian's code.
Code:
int a=234;
unsigned char buffer[10];

    itoa( a, buffer,10);
    display(buffer);

Mike.
 
Hello, showing error?

Warning [359] C:\Users\abc\Documents\mplab\scrolling.C; 26.16 illegal conversion between pointer types
pointer to const unsigned char -> pointer to unsigned char
Warning [357] C:\Users\abc\Documents\mplab\scrolling.C; 31.8 illegal conversion of integer to pointer
Warning [358] C:\Users\abc\Documents\mplab\scrolling.C; 31.15 illegal conversion of pointer to integer
Make: The target "C:\Users\abc\Documents\mplab\Font.p1" is up to date.
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC\9.83\bin\picc.exe" -oscrolling.C.cof -mscrolling.C.map --summary=default --output=default scrolling.p1 Font.p1 --chip=16F72 -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode) V9.83
Copyright (C) 2011 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Lite mode (warning)
Error [1347] ; 0. can't find 0x2A words (0x2a withtotal) for psect "text186" in class "CODE" (largest unused contiguous range 0x1C)
Error [1347] ; 0. can't find 0x21 words (0x21 withtotal) for psect "cinit" in class "CODE" (largest unused contiguous range 0x1C)
Error [1347] ; 0. can't find 0x8 words (0x8 withtotal) for psect "clrtext" in class "CODE" (largest unused contiguous range 0x2)

********** Build failed! **********
 
Hello,

Code:
#include <htc.h>
#include <stdlib.h>
__CONFIG( BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
#define DAD PORTB
#define RST RC5
#define CLK RC3
#define DATA RC4
extern const char Font2[];
void blit(char a), clear(void);
  unsigned char leds[30];
unsigned char buffer[30];

unsigned char pow[] = {0,128,64,32,16,8,4,2,1};
display(char *str);
int data( int p);
int t,r;
char b,e,v;
main (){
TRISC=0B00000000;
TRISB=0B00000000;


while(1){
clear();
display(" Led ");
blit(1);
int t=234;
unsigned char buffe[10];

    itoa( t, buffe,10);
    display(buffe);
blit(1);

}
}



display(char *str)  
{

int addr;                                                     
int z;
while(*str!=0){
addr = ((int)*str++ - 0x20);
addr *= 5;
int y=0;
for(z=0;z<5;z++){
        leds[z] = Font2[addr+y];
y++;
}
addr = ((int)*str++ - 0x20);
addr *= 5;
int y=0;
for(z=6;z<11;z++){
leds[z] = Font2[addr+y];
y++;
}
addr = ((int)*str++ - 0x20);
addr *= 5;
int y=0;
for(z=12;z<17;z++){
leds[z] = Font2[addr+y];
y++;
}
addr = ((int)*str++ - 0x20);
addr *= 5;
int y=0;
for(z=18;z<23;z++){
leds[z] = Font2[addr+y];
y++;
}
addr = ((int)*str++ - 0x20);
addr *= 5;
int y=0;
for(z=24;z<29;z++){
leds[z] = Font2[addr+y];
y++;

}


void blit(char a){
for(char x=0;x<40;x++){
for(char x=0;x<5;x++){
char u=-1;
b=0b00000001;
for(int r=0;r<8;r++){
DAD=pow[r];
__delay_ms(2);
RST=0;
RST=1;
u++;
for(int a=0;a<32;a++){
DAD=0;
RST=1;
char t,n;
n=leds[a];
n>>=u;
t=(n & b);
DATA=t;

CLK=1;
__delay_us(10);
CLK=0;
}}
}
{
if(a==1){
for(char x=0;x<32;x++){

//leds[x]>>=1;
}
}
if(a==3){
for(char x=0;x<32;x++){

leds[x]<<=1;
}
}
if(a==0){
for(char x=0;x<32;x++){

leds[x]=leds[x+1];
}
}
}
}

}





void clear(void){
for(char x=0;x<30;x++){
leds[x]=0;
}
}
 
The warning is because I think the itoa() needs a reference.. ie.. itoa( a, &buffer[0],10);

The errors are your code doesn't fit inside the pic.... Which pic are you using???
Hello again,
right now PIC16f72 it is working with small code size text!

after reference still have a problem
 
It looks like display needs a rom pointer. See if there is a display that takes a ram pointer or a function that prints 1 character.

edit didn't see later code, what line is the pointer error on?

Mike.
 
It looks like display needs a rom pointer. See if there is a display that takes a ram pointer or a function that prints 1 character.

Mike.
The display routine takes a char pointer to ram not rom... With Hi-tech a rom pointer has to use the const tag...
 
I hadn't noticed the code before I wrote that. Knowing which line the error is on would help.

Mike.
 
HELLO,

uild C:\Users\abc\Documents\mplab\scrolling.C for device 16F72
Using driver C:\Program Files (x86)\HI-TECH Software\PICC\9.83\bin\picc.exe

Make: The target "C:\Users\abc\Documents\mplab\scrolling.p1" is up to date.
Make Error: Can't open file "\". (3)
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\abc\Documents\mplab\Font.C -q --chip=16F72 -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC\9.83\bin\picc.exe" -oscrolling.C.cof -mscrolling.C.map --summary=default --output=default scrolling.p1 Font.p1 --chip=16F72 -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode) V9.83
Copyright (C) 2011 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Lite mode (warning)
Error [1347] ; 0. can't find 0x2A words (0x2a withtotal) for psect "text186" in class "CODE" (largest unused contiguous range 0x1C)
Error [1347] ; 0. can't find 0x21 words (0x21 withtotal) for psect "cinit" in class "CODE" (largest unused contiguous range 0x1C)
Error [1347] ; 0. can't find 0x8 words (0x8 withtotal) for psect "clrtext" in class "CODE" (largest unused contiguous range 0x2)

********** Build failed! **********
 
My god .... I have had trouble compiling this..
You really need to organize your code better.... In ansi C you can't just declare variables anywhere...

Read through this and see what changes I've made...
C:
#include <htc.h>
#include <stdlib.h>
#include <string.h>
__CONFIG( BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
#define DAD PORTB
#define RST RC5
#define CLK RC3
#define DATA RC4
extern const char Font2[];
void blit(char a), clear(void);
unsigned char leds[30];
unsigned char buffer[30];

unsigned char pow[] = {0,128,64,32,16,8,4,2,1};
void display(char *str), blit(char a);
int data( int p);
char b;

main ()
   {
   int t=234;
   TRISC=0B00000000;
   TRISB=0B00000000;

   while(1){
     clear();
     strcpy(buffer," Led ");
     display(buffer);
     blit(1);
    itoa( t, &buffer[0], 10);
    display(buffer);
     blit(1);
     }
   }



void display(char *str)
   {
   int addr;  
   int z,y;
   while(*str!=0)
     {
     addr = ((int)*str++ - 0x20);
     addr *= 5;
      y=0;
     for(z=0;z<5;z++)
       {
       leds[z] = Font2[addr+y];
       y++;
       }
     addr = ((int)*str++ - 0x20);
     addr *= 5;
     y=0;
     for(z=6;z<11;z++)
       {
       leds[z] = Font2[addr+y];
       y++;
       }
     addr = ((int)*str++ - 0x20);
     addr *= 5;
     y=0;
     for(z=12;z<17;z++)
       {
       leds[z] = Font2[addr+y];
       y++;
       }
     addr = ((int)*str++ - 0x20);
     addr *= 5;
     y=0;
     for(z=18;z<23;z++)
       {
       leds[z] = Font2[addr+y];
       y++;
       }
     addr = ((int)*str++ - 0x20);
     addr *= 5;
     y=0;
     for(z=24;z<29;z++)
       {
       leds[z] = Font2[addr+y];
       y++;
       }
     }
   }

void blit(char a)
   {
   char x,u,t,r,n;
   for(x=0;x<40;x++)
     {
     for(x=0;x<5;x++)
       {
       u=-1;
       b=0b00000001;
       for(r=0;r<8;r++)
         {
         DAD=pow[r];
         __delay_ms(2);
         RST=0;
         RST=1;
         u++;
         for(a=0;a<32;a++)
           {
           DAD=0;
           RST=1;
           n=leds[a];
           n >>= u;
           t=(n & b);
           DATA=t;

           CLK=1;
           __delay_us(10);
           CLK=0;
           }
         }
       }
     }
   if(a==1)
     {
     for(x=0;x<32;x++)
       //leds[x]>>=1;
     if(a==3)
       {
       for( x=0;x<32;x++)
         leds[x]<<=1;
       if(a==0)
         {
         for(x=0;x<32;x++)
           leds[x]=leds[x+1];
         }
       }
     }

   }


void clear(void)
   {
   for(char x=0;x<30;x++)
     leds[x]=0;
   }

This compiles on your chip in "Lite " mode BUT ONLY JUST!!! There is two 30 byte buffers you only need 1 20 byte buffer!!![/code]
 
Hello again,
This part is not working...
strcpy(buffer,"Led0"); // it is working
display(buffer);
blit(0);

int t=111; // this is not
itoa( t, buffer[0], 10);
display(buffer);
blit(1);
clear();
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top