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 support@ccsinfo.com

Problem with GLCD code posted by Konrad

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



Joined: 15 Jul 2005
Posts: 89
Location: UK

View user's profile Send private message

Problem with GLCD code posted by Konrad
PostPosted: Thu Mar 02, 2006 3:53 am     Reply with quote

Hi,

I'm trying out a bit of code that was posted by Konrad in this thread some time ago:

http://www.ccsinfo.com/forum/viewtopic.php?t=17576&highlight=bmp

I can get my bmp file to display ascross the whole screen i.e. acrross chip1 and chip2, but when I try and send some text to the screen using the code below, it displays it but it is copied into both halves of the screen. It's as if it's writing the text to both chips (x position, 0 - 63 and 64 - 127).

I'm using an Ampire 128x64 display from Crownhill Associates. The data sheet can be found here:

http://www.crownhill.co.uk/support/downloads/GLCD_data.zip

Can anyone offer any suggestions? It has to be something simple to do with the text positioning code as the bmp function works fine. This suggests that the hardware connections are ok. I just can't spot what might be causing it in the code. I'm using compiler version 3.242.

Cheers,
Ed

Code:


// My main code:

#include <18F6722.h>

#FUSES HS, NOLVP, NOWDT, NOPROTECT            // Fuses

#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=PORT1)   
#use rs232(baud=9600, xmit=PIN_G1, rcv=PIN_G2, stream=PORT2)   

#include <ds1621_clino.c>
#include <ds1302_clino.c>
#include <lcd_bmp.c>


void main()
{

/* Variables */

float temp;
float temp2;
int time, hr, min, sec;

/* Initialise */

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(VREF_LOW|-2);
   setup_low_volt_detect(LVD_40|LVD_TRIGGER_BELOW);
   setup_oscillator(False);

   init_temp();                             // Init DS1621
   rtc_init();                                // Init DS1302

   lcd_init();                                // Init bmp code
   lcd_load_bmp();                      // Print welcome message
   delay_ms(4000);
   lcd_clrscr();                            // Clear screen


/* Main Loop */

   while (1)
     {
      output_toggle(PIN_C2);
      temp = read_full_temp();
      rtc_get_time(hr,min,sec);

      temp2 = (temp-32)/1.8;
     
      lcd_gotoxy(0,1);                                    // xy position in characters
      printf(lcd_putc, "T = %2.1f F\n", temp);
      printf(lcd_putc, "T = %2.1f C\n", temp2);
      lcd_gotoxy(0,6);
      printf(lcd_putc, "%02u:%02u:%02u\n", hr,min,sec);
      }
}


Code:


// Driver code - modded pin locations

#include "bmp_test.c" //chr const bmp[1024] ~ picture in format (8 x 128) x 8
// visit www.compsys1.com/workbench

#byte PORTA= 0x0F80
#byte PORTB= 0x0F81
#byte PORTC= 0x0F82
#byte PORTD= 0x0F83
#byte PORTE= 0x0F84
#byte PORTF= 0x0F85

// the screen is built
//chip 1 chip 2
//1 - > 64 1 - > 64
//::----:: ::----:: byte byte
//::----:: ::----:: " "
//::----:: ::----:: " "
//::----:: ::----:: " "
//
//::----:: ::----::
//::----:: ::----::
//::----:: ::----::
//::----:: ::----::
//etc, 8 horizontal lines

//board specific definitions for pins
#define lcd_cs1      PIN_F5     //ChipSelect1 Pin 13 on LCD
#define lcd_cs2      PIN_F4     //ChipSelect2 Pin 12 on LCD
#define lcd_cmd      PIN_F0     //Data/Command Pin 16 on LCD
#define lcd_rw       PIN_F1     //Read/Write Pin 15 on LCD
#define lcd_enable   PIN_F2     //Enable pin 17 on LCD
#define lcd_rst      PIN_F3     //Reset Pin 14 on LCD


#byte lcd_data = PORTD     //ensure PORTD is declared as a byte
#use fast_io(D)

#define LCD_LEFT 1
#define LCD_RIGHT 0

void lcd_init(void);
void lcd_write(int1 half);
void lcd_gotoxy(int8 x, int8 y);
void lcd_clrscr(void);
void lcd_newline(void);
void lcd_load_bmp(void);

CHAR CONST fonts[475]= { //dec ascii
0x00,0x00,0x00,0x00,0x00, //32 <Space>
0x00,0x00,0x4F,0x00,0x00, //33 !
0x00,0x07,0x00,0x07,0x00, //34 "
0x14,0x7F,0x14,0x7F,0x14, //35 #
0x24,0x2A,0x7F,0x2A,0x12, //36 $
0x23,0x13,0x08,0x64,0x62, //37 %
0x36,0x49,0x55,0x22,0x50, //38 &
0x00,0x05,0x03,0x00,0x00, //39 '
0x1C,0x22,0x41,0x00,0x00, //40 (
0x00,0x00,0x41,0x22,0x1C, //41 )
0x14,0x08,0x3E,0x08,0x14, //42 *
0x08,0x08,0x3E,0x08,0x08, //43 +
0x00,0x50,0x30,0x00,0x00, //44 ,
0x08,0x08,0x08,0x08,0x08, //45 -
0x00,0x60,0x60,0x00,0x00, //46 .
0x20,0x10,0x08,0x04,0x02, //47 /
0x3E,0x51,0x49,0x45,0x3E, //48 0
0x00,0x42,0x7F,0x40,0x00, //49 1
0x42,0x61,0x51,0x49,0x46, //50 2
0x21,0x41,0x45,0x4B,0x31, //51 3
0x18,0x14,0x12,0x7F,0x10, //52 4
0x27,0x45,0x45,0x45,0x39, //53 5
0x3C,0x4A,0x49,0x49,0x30, //54 6
0x01,0x71,0x09,0x05,0x03, //55 7
0x36,0x49,0x49,0x49,0x36, //56 8
0x06,0x49,0x49,0x49,0x3E, //57 9
0x00,0x36,0x36,0x00,0x00, //58 :
0x00,0x56,0x36,0x00,0x00, //59 ;
0x08,0x14,0x22,0x41,0x00, //60 <
0x14,0x14,0x14,0x14,0x14, //61 =
0x00,0x41,0x22,0x14,0x08, //62 >
0x02,0x01,0x51,0x09,0x06, //63 ?
0x32,0x49,0x79,0x41,0x3E, //64 @
0x7E,0x11,0x11,0x11,0x7E, //65 A
0x7F,0x49,0x49,0x49,0x36, //66 B
0x3E,0x41,0x41,0x41,0x22, //67 C
0x7F,0x41,0x41,0x22,0x1C, //68 D
0x7F,0x49,0x49,0x49,0x41, //69 E
0x7F,0x09,0x09,0x09,0x01, //70 F
0x3E,0x41,0x49,0x49,0x7A, //71 G
0x7F,0x08,0x08,0x08,0x7F, //72 H
0x00,0x41,0x7F,0x41,0x00, //73 I
0x20,0x40,0x41,0x3F,0x01, //74 J
0x7F,0x08,0x14,0x22,0x41, //75 K
0x7F,0x40,0x40,0x40,0x40, //76 L
0x7F,0x02,0x0C,0x02,0x7F, //77 M
0x7F,0x04,0x08,0x10,0x7F, //78 N
0x3E,0x41,0x41,0x41,0x3E, //79 O
0x7F,0x09,0x09,0x09,0x06, //80 P
0x3E,0x41,0x51,0x21,0x5E, //81 Q
0x7F,0x09,0x19,0x29,0x46, //82 R
0x46,0x49,0x49,0x49,0x31, //83 S
0x01,0x01,0x7F,0x01,0x01, //84 T
0x3F,0x40,0x40,0x40,0x3F, //85 U
0x1F,0x20,0x40,0x20,0x1F, //86 V
0x3F,0x40,0x38,0x40,0x3F, //87 W
0x63,0x14,0x08,0x14,0x63, //88 X
0x07,0x08,0x70,0x08,0x07, //89 Y
0x61,0x51,0x49,0x45,0x43, //90 Z
0x7F,0x41,0x41,0x00,0x00, //91 [
0x02,0x04,0x08,0x10,0x20, //92 \
0x00,0x00,0x41,0x41,0x7F, //93 ]
0x04,0x02,0x01,0x02,0x04, //94 ^
0x40,0x40,0x40,0x40,0x40, //95 _
0x00,0x01,0x02,0x04,0x00, //96 `
0x20,0x54,0x54,0x54,0x78, //97 a
0x7F,0x48,0x44,0x44,0x38, //98 b
0x38,0x44,0x44,0x44,0x20, //99 c
0x38,0x44,0x44,0x48,0x7F, //100 d
0x38,0x54,0x54,0x54,0x18, //101 e
0x08,0x7E,0x09,0x01,0x02, //102 f
0x0C,0x52,0x52,0x52,0x3E, //103 g
0x7F,0x08,0x04,0x04,0x78, //104 h
0x00,0x44,0x7D,0x40,0x00, //105 i
0x00,0x20,0x40,0x44,0x3D, //106 j
0x7F,0x10,0x28,0x44,0x00, //107 k
0x00,0x41,0x7F,0x40,0x00, //108 l
0x7C,0x04,0x18,0x04,0x78, //109 m
0x7C,0x08,0x04,0x04,0x78, //110 n
0x38,0x44,0x44,0x44,0x38, //111 o
0x7C,0x14,0x14,0x14,0x08, //112 p
0x08,0x14,0x14,0x18,0x7C, //113 q
0x7C,0x08,0x04,0x04,0x08, //114 r
0x48,0x54,0x54,0x54,0x20, //115 s
0x04,0x3F,0x44,0x40,0x20, //116 t
0x3C,0x40,0x40,0x20,0x7C, //117 u
0x1C,0x20,0x40,0x20,0x1C, //118 v
0x3C,0x40,0x30,0x40,0x3C, //119 w
0x44,0x28,0x10,0x28,0x44, //120 x
0x0C,0x50,0x50,0x50,0x3C, //121 y
0x44,0x64,0x54,0x4C,0x44, //122 z
0x08,0x36,0x41,0x00,0x00, //123 {
0x00,0x00,0x7F,0x00,0x00, //124 |
0x00,0x00,0x41,0x36,0x08, //125 }
0x00,0x08,0x04,0x08,0x04 //126 ~
};

//position on LCD, x = 0 - 127, y = 0 - 7
int8 x_position, y_position;

#define CS1_MAX_X 63 //chip 1 x range 0 - 63
#define CS2_MAX_X 127 //chip 1 x range 64 - 127

#define DISPLAY_ON 0x3F //LCD Display ON
#define DISPLAY_OFF 0x3E //LCD Display OFF
#define SET_X 0x40 //LCD SET X command, add x - 0 to 63
#define SET_Y 0xB8 //LCD SET Y command, add y - 0 to 7
#define SET_RAM_0 0xC0 //LCD RAM, used for scrolling add x - 0 to 63

void lcd_init(void)
{

//init LCD lines
set_tris_d(0x00);
lcd_data = 0x00;
output_high(lcd_cmd);
output_low(lcd_rw);
output_low(lcd_enable);
output_low(lcd_cs1);
output_low(lcd_cs2);

//reset LCD
output_high(lcd_rst);
delay_us(10);
output_low(lcd_rst);
delay_us(5);
output_high(lcd_rst);
delay_us(10);

//command mode
output_low(lcd_cmd);
lcd_data = DISPLAY_OFF;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);
lcd_data = SET_RAM_0;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);
lcd_gotoxy(0,0);
lcd_data = DISPLAY_ON;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);
output_high(lcd_cmd);

x_position = 0;
y_position = 0;

return;
}



void lcd_write(int1 half)
{
   if(half)
    {
      output_high(lcd_cs1);
      output_low(lcd_cs2);
    }
   else
    {
      output_low(lcd_cs1);
      output_high(lcd_cs2);
    }

delay_us(2);
output_high(lcd_enable);
delay_us(2);
output_low(lcd_enable);
delay_us(2);

return;
}



void lcd_clrscr(void)
{
int8 x,y;

output_low(lcd_cmd);

lcd_data = DISPLAY_OFF;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);

output_high(lcd_cmd);

for(y=0; y<8; y++)
  {
    output_low(lcd_cmd);

    lcd_data = SET_Y + y;
    lcd_write(LCD_LEFT);
    lcd_write(LCD_RIGHT);

    output_high(lcd_cmd);

for(x=0; x<64; x++)
   {
    lcd_data = 0;
    lcd_write(LCD_LEFT);
    lcd_write(LCD_RIGHT);
   }
 }

output_low(lcd_cmd);

lcd_data = DISPLAY_ON;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);

output_high(lcd_cmd);

lcd_gotoxy(0,0);

return;
}


void lcd_putc( char c)
{
int16 index,count;
int8 x;

   switch (c)
      {
      case '\f' :
      lcd_clrscr();
      break;

      case '\n' :
      lcd_newline();
      break;

      default :

         //check there is space to print
      if((x_position + 5) < CS2_MAX_X)
        { //print character
          index = (int16)(c - 32) * 5;

               for(x=0; x<5; x++)
                {
                lcd_data = fonts[index++];
                  if(x_position > CS1_MAX_X)
                   {
                  lcd_write(LCD_RIGHT);
                   }
                  else
                  {
                  lcd_write(LCD_LEFT);
                  }

                  x_position++;
                }
            }

      if((x_position + 1) < CS2_MAX_X)
      {
      lcd_data = 0x00;
         if(x_position > CS1_MAX_X)
         {
         lcd_write(LCD_RIGHT);
         }
         else
         {
         lcd_write(LCD_LEFT);
         }
         x_position++;
      }
   break;
      }

return;
}



int8 lcd_read_byte( void )
{

}



void lcd_gotoxy( int8 x, int8 y)             // Integer line/char position (5x7 char)
{
x_position = x;
y_position = y;

output_low(lcd_cmd);
if(x > 63)
{
x = x - 63;
lcd_data = SET_X + x;
lcd_write(LCD_RIGHT);

lcd_data = SET_X;
lcd_write(LCD_LEFT);
}
else
{
lcd_data = SET_X + x;
lcd_write(LCD_LEFT);

lcd_data = SET_X;
lcd_write(LCD_RIGHT);
}

lcd_data = SET_Y + y;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);
output_high(lcd_cmd);

return;
}


void lcd_newline(void)
{
x_position = 0;

if(y_position < 7) //check for last line
{
y_position ++;

output_low(lcd_cmd);
lcd_data = SET_X;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);
lcd_data = SET_Y + y_position;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);
output_high(lcd_cmd);
}

return;
}


void lcd_load_bmp(void)
{
int8 x,y;
int16 ptr=0;


// output_low(lcd_cmd);

// lcd_data = DISPLAY_OFF;
// lcd_write(LCD_LEFT);
// lcd_write(LCD_RIGHT);

// output_high(lcd_cmd);

for(y=0; y<8; y++)
{
output_low(lcd_cmd);

lcd_data = SET_Y + y;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);

output_high(lcd_cmd);

for(x=0; x<64; x++)
{
lcd_data = bmp[ptr++];
lcd_write(LCD_LEFT);
}
for(x=0; x<64; x++)
{
lcd_data = bmp[ptr++];
lcd_write(LCD_RIGHT);
}
}

output_low(lcd_cmd);

lcd_data = DISPLAY_ON;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);

output_high(lcd_cmd);

lcd_gotoxy(0,0);

return;
}
 
edhaslam



Joined: 15 Jul 2005
Posts: 89
Location: UK

View user's profile Send private message

PostPosted: Fri Mar 03, 2006 6:45 am     Reply with quote

This is now fixed. By changing this line:

Code:

setup_vref(VREF_LOW|-2);


to:

Code:

setup_vref(FALSE);


I had one of the chip select pins on F5 (vref) hence the strange behaviour across the screen.
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