|
|
View previous topic :: View next topic |
Author |
Message |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
#Define of a print function - Still not working / Full code |
Posted: Thu Aug 14, 2014 9:44 pm |
|
|
Hi all,
Im working a simple driver for an old VFD display.
It works fine but while converting it to a "Driver" i wanted to do the following:
Currently i print to the screen like so:
Code: | Printf(Subset,"\n\r1.2.3.A.B.C.x.y.z.a.b.c.X.Y.Z.@."); |
But i think it looks prettier like so:
Code: | Print_VFD("\n\r1.2.3.A.B.C.x.y.z.a.b.c.X.Y.Z.@."); |
So im trying to make a define that will allow me to replace
Printf(Subset, with Print_VFD(
Subset(char) is a function necessary to handle the commas and periods on the screen.
The driver will be up in the library as soon as i get this done with.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093
Last edited by Gabriel on Sat Aug 16, 2014 2:31 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 14, 2014 10:15 pm |
|
|
I'm not totally sure what you want, but this is an example.
It produces this output in MPLAB simulator:
Quote: | 1,2,3,A,B,C,x,y,z,a,b,c,X,Y,Z,@, |
Test program:
Code: | #include <18F4620.h>
#fuses INTRC_IO, BROWNOUT, PUT, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
// This is some kind of filter function.
// Internals are unknown, so make it
// replace periods with a comma, just
// to have it do something.
void Subset(char c)
{
if(c == '.')
putc(',');
else
putc(c);
}
#define Print_VFD(x) printf(Subset, x)
//===================================
void main()
{
Print_VFD("\n\r1.2.3.A.B.C.x.y.z.a.b.c.X.Y.Z.@.");
while(1);
} |
|
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sat Aug 16, 2014 7:06 am |
|
|
Hi PCM,
Thanks for the reply.
I only got a chance to compile my code with your changes and it did... sorta.
When printing things like '\'' it gives me a define error.
It seems to be working for all characters not requiring an escape character.
I'll let you know how it goes later today when get to fully test it.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sat Aug 16, 2014 8:57 am |
|
|
That is standard C.....
Because the '\' character, is used as the 'intro' character for the escapes (\n, \r etc.), it can't be used as a single character in a string.
The escape to send backslash, is "\\". Any C textbook, and the CCS manual (though it takes a bit of finding), will tell you this (do a search for the word 'backslash'). |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sat Aug 16, 2014 2:06 pm |
|
|
Hi Ttelmah,
I am well aware of the properties of \ while printing.
My point was that:
Code: | Printf(Subset,"abc, \', yxz"); |
works just fine, but:
Code: | Print_VFD("abc, \', yxz"); |
Does not.
Something changes when using the #define as proposed by PCM.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sat Aug 16, 2014 2:29 pm |
|
|
Full Code below:
The problem persists...
Code: | #include <16f886.h>
#device adc=8
#device *=16
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NODEBUG
#use delay(clock=20000000)
#include "FLIP_VFD_1x16.c"
//==========================
void main()
{
while(1)
{
putc(EOL_MODE3); // set screen wraping mode
//Test escape characters
//Print_VFD("\n\r---- \' \" \\ ----");
Printf(Subset,"\n\r---- \' \" \\ ----");
delay_ms(3000);
//Test Symbols with periods & commas
Print_VFD("\n\r#,. ,?,.%,$.*,/.+.-,}{_.(,");
delay_ms(3000);
//Test Letters with periods & commas
Print_VFD("\n\ra,b,c,x,y,z,@.A.B.C.X.Y.Z.");
delay_ms(3000);
}
} |
"Driver":
Code: | #define COMM_PIN PIN_B0 // Serial pin to talk to VFD
#define CLR_DISPLAY 0x0A // AKA: Line Feed - '\n'
#define CR_RETURN 0x0D // AKA: Return '\r'
#define BACK_SPACE 0x08
#define FWD_SPACE 0x09
#define BLINK 0x0B
#define NO_BLINK 0x0C
#define VIEW_CURSOR 0x0F
#define HIDE_CURSOR 0x0E
#define EOL_MODE1 0x11 // Default - Automatic CR
#define EOL_MODE2 0x12 // Overwrite Rightmost char
#define EOL_MODE3 0x13 // Scroll right to left
#define Print_VFD(x) Printf(Subset,x) // Print Handle for Easier coding
#use rs232(baud=1200, xmit=COMM_PIN,STOP=2, ERRORS) // Software Serial
char Previous_Char; // Global Var
void Subset(char); // Fuction Declaration
void Subset(char Next_Char)
{
if((Next_Char=='.')&&(Previous_Char<0x80)&&(Previous_Char!='.'))
{
putc(BACK_SPACE);
if((Previous_Char>0x60)&&(Previous_Char<0x7B))
{
Previous_Char-=0x20;
}
Next_Char=Previous_Char|0x80;
}
if((Next_Char==',')&&(Previous_Char>0x3F)&&(Previous_Char!=','))
{
putc(BACK_SPACE);
if((Previous_Char>0x60)&&(Previous_Char<0x7B))
{
Previous_Char-=0x20;
}
Next_Char=Previous_Char|0xA0;
}
if((Next_Char==',')&&(Previous_Char<0x40)&&(Previous_Char!=','))
{
putc(BACK_SPACE);
Next_Char=Previous_Char+0x60;
}
putc(Next_Char);
Previous_Char=Next_Char;
} |
When testing the escape chars, using the #define "macro" does not compile. however using the normal Printf works fine.
I hope that helps you help me.
Kind regards,
G _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Aug 16, 2014 3:45 pm |
|
|
Quote: | When testing the escape chars, using the #define "macro" does not compile.
//Test escape characters
//Print_VFD("\n\r---- \' \" \\ ----"); |
If you use the Octal code (\042) instead of the double quote (\"),
then it compiles. Example:
Code: | Print_VFD("\n\r---- \' \042 \\ ----"); |
The line above displays this output:
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sun Aug 17, 2014 1:43 am |
|
|
You don't have to do this. Simply redefine PCM's macro as:
Code: |
#define Print_VFD(x) Printf(Subset,#x) // Print Handle for Easier coding
|
The problem is 'double expansion'. When a string is passed like this in a macro, the macro language 'parses' the internal constants. So what arrives at the final code, is already expanded.
To do a 'raw' pass, adding the # to the macro definition, prevents this parsing.
However there are a couple of other 'problem' characters in your string.
The '%' remember, is the format specifier for printf, and you have it in your 'symbols' example. This needs to be passed as %%:
Code: |
Print_VFD("\n\r#,. ,?,.%%,$.*,/.+.-,}{_.(,");
|
|
|
|
|
|
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
|