Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/04/04 17:04
Read: times


 
#75418 - RE: ° LCD (44780) works in only ASM not C! °
Responding to: ???'s previous message
I'll probably get fried for this, but what the heck, whats life without some risk to pride.

Here is some code that works for me on a SILABS C8051F040, using digital IO to run a noritake GUI140X32F-7000 (3.3V version). This is the test program I used. In the real application, the display is the least critical element. Memory is pretty cheap, so I had (actually have, as this project is temporarily on hold) to minimize the time spent handling the display.

This will definitley not compile for you as is, so don't try. I do have functions set up for writing sigle character to display, polling for completion of write (I hate using delays), clearing the display (this is the only one that actually waits to be done, haven't had time to fix this yet), and a really long funtion that sets up screen formatting (but it runs faster and with less code than using sprintf)

Hope I got the HTML tags right, this is my first time posting code, but will not know until I post it, so here goes.........................

Andy


pre

#include "C:KEILAMSC_C_SOFTAMSC_SRCC8051F04xc8051f040.h"
#include "C:KEILAMSC_C_SOFTAMSC_SRCC8051F04xtiming_1.0.h"
#include "C:KEILAMSC_C_SOFTAMSC_SRCC8051F04xdigital_1.0.h"
#include "C:KEILAMSC_C_SOFTAMSC_SRCC8051F04xana_func_1.0.h"
#include <string.h>
#define VREF 2.5 //voltage reference
sbit PBUSY=P5 ^7;
sbit WRITE=P4 ^6;
sbit READ=P4 ^ 7;
sbit timing=P2^0;
float current,v1,v2,v3;
unsigned int vfd_counter;
xdata unsigned char display[60];
void write_char(char wchar);
bit check_done(void);
void clear_vfd(void);
void make_screen_1(void);
unsigned int AtoD0_get_praw(void);
void main()
{
unsigned int EXC_uC_temp;
unsigned char i;
bit check_once;
disable_watchdog();
external_osc();
TMR3_timer(63693,1); //sets timer 3 to generate interupt every 1mS
xbar(1);
port4_setup(0xC0,0x00,0xC0);
memset(&display,'',sizeof(display));
init_Vref(1,1,1); //turn on referance and internal temp sensor

AtoD0_cntrl_scheme(1); //init A to D
clear_vfd();
vfd_counter=0;
current=123.456;
v1=2.468;
v2=1.357;
v3=3.141;
check_once=0;
EA=1;
while(1)
{

if ((vfd_counter > 1000)&& !check_once)
{
check_once=1;
clear_vfd();
timing=0;
make_screen_1();
timing=1;
EXC_uC_temp=AtoD0_get_praw();
}
if (check_once)
{
if (!check_done())
{
write_char(display[i]);
i++;
if (i == strlen(display))
{
i=0;
check_once=0;
vfd_counter=0;
}
}
}
}
}
void TR3_increment (void) interrupt 14 //timer 3 interupt, called every 1 mS
{
unsigned char SFRPAGE_SAVE;
SFRPAGE_SAVE = SFRPAGE; //Save SFR page context
SFRPAGE=TMR3_PAGE;
TF3=0; //clear interupt
vfd_counter++;

SFRPAGE = SFRPAGE_SAVE;
}
void write_char(char wchar)
{
unsigned char SFRPAGE_SAVE;
SFRPAGE_SAVE = SFRPAGE; //Save SFR page context
SFRPAGE=CONFIG_PAGE;
//port5_setup(0xFF,0x00,0xff); //set to write
P5MDOUT=0xFF; //set to push_pull
PBUSY=1;
READ=1; //disable read,
WRITE=0; //enable write
//write_port5(wchar); //write character to port 5
P5=wchar;
WRITE=1; //DISABLE WRITE
//port5_setup(0x80,0x80,0x00); //set to read
P5MDOUT=0x00; //set to open drain
P5=0xFF;
READ=0; //ENABLE READ
SFRPAGE = SFRPAGE_SAVE;
}
bit check_done(void)
{
unsigned char SFRPAGE_SAVE;
bit checker;
SFRPAGE_SAVE = SFRPAGE; //Save SFR page context
SFRPAGE=CONFIG_PAGE;
checker=PBUSY;
SFRPAGE = SFRPAGE_SAVE;
return checker;
}
void clear_vfd(void)
{
unsigned char SFRPAGE_SAVE;
SFRPAGE_SAVE = SFRPAGE; //Save SFR page context
SFRPAGE=CONFIG_PAGE;
PBUSY=0;
write_char(0x0C);
while (PBUSY);
SFRPAGE = SFRPAGE_SAVE;
}

void make_screen_1(void)
{
unsigned char temper,decer;
display[0]='I';
display[1]='(';
display[2]='A';
display[3]=')';
display[4]='=';

temper=(unsigned char)current;
decer=((unsigned int)(current*10)%10);
display[7]=((unsigned char)(temper%10))+48;
temper=temper /10;
display[6]=((unsigned char)(temper%10))+48;
if (display[6]=='0') display[6]=' ';
temper=temper /10;
display[5]=((unsigned char)(temper%10))+48;
if (display[5]=='0') display[5]=' ';
display[8]='.';
display[9]=decer+48;
display[10]='n';
display[11]='r';

display[12]='V';
display[13]='1';
display[14]='(';
display[15]='V';
display[16]=')';
display[17]='=';

temper=(unsigned char)v1;
decer=((unsigned int)(v1*10)%10);
display[20]=((unsigned char)(temper%10))+48;
temper=temper /10;
display[19]=((unsigned char)(temper%10))+48;
if (display[19]=='0') display[19]=' ';
temper=temper /10;
display[18]=((unsigned char)(temper%10))+48;
if (display[18]=='0') display[18]=' ';
display[21]='.';
display[22]=decer+48;
display[23]='n';
display[24]='r';

display[25]='V';
display[26]='2';
display[27]='(';
display[28]='V';
display[29]=')';
display[30]='=';

temper=(unsigned char)v2;
decer=((unsigned int)(v2*10)%10);
display[33]=((unsigned char)(temper%10))+48;
temper=temper /10;
display[32]=((unsigned char)(temper%10))+48;
if (display[32]=='0') display[32]=' ';
temper=temper /10;
display[31]=((unsigned char)(temper%10))+48;
if (display[31]=='0') display[31]=' ';
display[34]='.';
display[35]=decer+48;
display[36]='n';
display[37]='r';

display[38]='V';
display[39]='3';
display[40]='(';
display[41]='V';
display[42]=')';
display[43]='=';

temper=(unsigned char)v3;
decer=((unsigned int)(v3*10)%10);
display[46]=((unsigned char)(temper%10))+48;
temper=temper /10;
display[45]=((unsigned char)(temper%10))+48;
if (display[45]=='0') display[45]=' ';
temper=temper /10;
display[44]=((unsigned char)(temper%10))+48;
if (display[44]=='0') display[44]=' ';
display[47]='.';
display[48]=decer+48;
display[49]='n';
display[50]='r';
display[51]=0;

}
unsigned int AtoD0_get_praw(void)
{
char_to_int AtoD;
int value;
unsigned char SFRPAGE_SAVE;
SFRPAGE_SAVE = SFRPAGE; //Save SFR page context
SFRPAGE = ADC0_PAGE;
AD0BUSY=1; //start conversion
while(AD0INT==0); //poll for end of conversion
AtoD.bytes[1]=ADC0L;
AtoD.bytes[0]=ADC0H;
AD0INT=0; //reset interupt
value=AtoD.integ;
SFRPAGE = SFRPAGE_SAVE;
return value;
}
/pre

List of 43 messages in thread
TopicAuthorDate
° LCD (44780) works in only ASM not C! °            01/01/70 00:00      
   RE: ° LCD (44780) works in only ASM not            01/01/70 00:00      
      Reply: Keil uVision limits            01/01/70 00:00      
         RE: Reply: Keil uVision limits            01/01/70 00:00      
            Reply to Bartosz Wucke...            01/01/70 00:00      
   RE: ° LCD (44780) works in only ASM not C! °            01/01/70 00:00      
      RE: ° LCD (44780) works in only ASM not C! °            01/01/70 00:00      
         oops-lets try tis again for the code            01/01/70 00:00      
            RE: oops-lets try tis again for the code            01/01/70 00:00      
               RE: oops-lets try tis again for the code            01/01/70 00:00      
   Reply to Ijaz: Comments + my code...            01/01/70 00:00      
      RE: Reply to Ijaz: Comments + my code...            01/01/70 00:00      
         Oleg: Thanks but no success...            01/01/70 00:00      
   RE: ° LCD (44780) works in only ASM not            01/01/70 00:00      
      RE: ° LCD (44780) works in only ASM not            01/01/70 00:00      
   RE: ° LCD (44780) works in only ASM not C! °            01/01/70 00:00      
      RE: ° LCD (44780) works in only ASM not            01/01/70 00:00      
      RE: ° LCD (44780) works in only ASM not            01/01/70 00:00      
         RE: ° LCD (44780) works in only ASM not            01/01/70 00:00      
            RE: ° LCD (44780) works in only ASM not            01/01/70 00:00      
               RE: ° LCD (44780) works in only ASM not            01/01/70 00:00      
               A scope IS a magic wand!            01/01/70 00:00      
                  Oh no it isnt!            01/01/70 00:00      
                     RE: Oh no it isnt!            01/01/70 00:00      
                        RE: Oh no it isnt!            01/01/70 00:00      
                     RE: Oh no it isnt!            01/01/70 00:00      
                        Fix it!!            01/01/70 00:00      
   Reply to Erik, Russell, Bartosz---            01/01/70 00:00      
      RE: Reply to Erik, Russell, Bartosz---            01/01/70 00:00      
      RE: Reply to Erik, Russell, Bartosz---            01/01/70 00:00      
   RE: ° LCD (44780) works in only ASM not C! °            01/01/70 00:00      
      Reply to Kai            01/01/70 00:00      
         RE: Reply to Kai            01/01/70 00:00      
            uVision Project LCD            01/01/70 00:00      
   RE: ° LCD (44780) works in only ASM not C! °            01/01/70 00:00      
      RE: memory mapped LCD            01/01/70 00:00      
      Erik, Russell, Kai...LCD Code...            01/01/70 00:00      
         RE: Erik, Russell, Kai...LCD Code...            01/01/70 00:00      
   It is time to take a look with the scope            01/01/70 00:00      
   Thanks..and final comments...            01/01/70 00:00      
      UPDATE: Traced problem to LCALL...            01/01/70 00:00      
         RE: UPDATE: Traced problem to LCALL...            01/01/70 00:00      
            Reply to Jon..            01/01/70 00:00      

Back to Subject List