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

HCMS-2903 5X7 Display

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



Joined: 21 Apr 2008
Posts: 18

View user's profile Send private message

HCMS-2903 5X7 Display
PostPosted: Fri Mar 27, 2009 4:19 am     Reply with quote

I am using a PIC 16f690 and trying to use a HCMS-2903 display. I have been able to display characters on the display.
Heres an example of what i got:
Code:
#include <16F690.h>
#device adc=10
#fuses NOWDT, BROWNOUT
#use delay(clock=4000000)
 

// Pin 1 Data Out Not used
// Pin 2 OSC Not used
// Pin 3 V LED Not used
#define dat Pin_C7 // Pin 4 Data in
#define rs Pin_C1 // Pin 5 RS
#define clock Pin_B6 // Pin 6 CLK
#define ce Pin_C6// Pin 7 CE
#define blank Pin_C4// Pin 8 Blank
// Pin 9 GND Not used
// Pin 10 SEL to VCC
// Pin 11 V Logic to VCC
// Pin 12 RESET to VCC


#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)


void display (int reg) //Function to write to register
{
  output_low(Pin_C6);
  spi_write(reg);
  output_high(Pin_C6);
}

int num_0[5] = {0b00111110,
                0b01000001,
                0b01001001,
                0b01000001,
                0b00111110};

int num_1[5] = {0b00000000,
                0b01000010,
                0b01111111,
                0b01000000,
                0b00000000};
               
int num_2[5] = {0b01110010,
                0b01001001,
                0b01001001,
                0b01001001,
                0b01000110};

int num_3[5] = {0b00100010,
                0b01000001,
                0b01001001,
                0b01001001,
                0b00110110};
               

void main(void)
{
  int i;
 
  setup_spi (SPI_MASTER| SPI_MODE_0 |SPI_CLK_DIV_64);
 
  delay_ms(10);
 
  output_high(rs);
  delay_ms(1);
  display(0b01111111);
  delay_ms(1);
 
  output_low(rs);
   
    for (i=0;i<5;i++)
  {
   delay_us(10);
   display(num_1[i]);
  }   

    for (i=0;i<5;i++)
  {
   delay_us(10);
   display(num_0[i]);
  }   

    for (i=0;i<5;i++)
  {
   delay_us(10);
   display(num_3[i]);
  }   

    for (i=0;i<5;i++)
  {
   delay_us(10);
   display(num_2[i]);
  }   

}
 

I am wondering if there is an easier way to accomplish this. Is there a way i can use printf so it is easier to update the display??
Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 27, 2009 11:25 am     Reply with quote

Yes. Write an "hcms_putc" function that displays one character. The input parameter to the function should be an ascii value. Then, use the special feature of the CCS printf function to re-direct the output of printf to your character display function.
Code:

void hcms_putc(int8 c)
{
// Put code here to index into a segment data
// table, and send the appropriate bytes to the
// HCMS-2903 to display the character.

}


void main()
{
init_hcms();

printf(hcms_putc, "Hello World");

while(1);
}

Here are two examples, using segmented LCDs, of how this is done.
Each of them has an lcd_putc() function that does the real work of writing
one character to the LCD display. Then printf can be used to send
characters (one by one) to the lcd_putc() function.
http://www.ccsinfo.com/forum/viewtopic.php?t=32774&start=8
http://www.ccsinfo.com/forum/viewtopic.php?t=33377&start=11
williefeb_19



Joined: 21 Apr 2008
Posts: 18

View user's profile Send private message

PostPosted: Fri Mar 27, 2009 9:26 pm     Reply with quote

I have look at the links but I don't understand how I would do that sort of thing with this dot matrix display. It has to load five sets of binary or hex for one digit and there are four of them. Would I do the character map like I am doing it now.
Code:

display layout
//////////////////////////////////////////////////////
X X X X X    X X X X X    X X X X X    X X X X X 
X X X X X    X X X X X    X X X X X    X X X X X
X X X X X    X X X X X    X X X X X    X X X X X
X X X X X    X X X X X    X X X X X    X X X X X
X X X X X    X X X X X    X X X X X    X X X X X
X X X X X    X X X X X    X X X X X    X X X X X
//////////////////////////////////////////////////////

int num_1[5] = {
                0b00000000,  //Number 1
                0b01000010,
                0b01111111,
                0b01000000,
                0b00000000};

The two example's posted use 14 or 7 segment lcd display's.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 27, 2009 11:45 pm     Reply with quote

Look at the glcd_text57() function in the glcd.c driver. It sends out 5
bytes to display one character. It uses a 2-dimensional array to
store the character data. Actually, because the PCM compiler has a
limit on the 'const' array size, it uses two arrays to store the entire
character set. Here's the driver location:
Quote:
c:\Program Files\picc\Drivers\glcd.c

Look at the glcd_text57() function, and also look at the two arrays that
store the character set:
Code:

const BYTE TEXT[51][5]

const BYTE TEXT2[44][5]
williefeb_19



Joined: 21 Apr 2008
Posts: 18

View user's profile Send private message

PostPosted: Sun Mar 29, 2009 8:23 pm     Reply with quote

I've looked over glcd.c my skills with C are not advanced enough yet to write that kind of driver. I get what most of it is doing but not all of it. I have been able to get the 2d array working and am able to display numbers 0-9. I have found a little bit of code on the forum that I have used for separating the digits.

Array:
Code:
const BYTE NUM[11][5] = {
0b00111110, // 0
0b01000001,
0b01001001,
0b01000001,
0b00111110,

0b00000000, // 1
0b01000010,
0b01111111,
0b01000000,
0b00000000,

0b01110010, // 2
0b01001001,
0b01001001,
0b01001001,
0b01000110,

0b00100010, // 3
0b01000001,
0b01001001,
0b01001001,
0b00110110,

0b00011000, // 4
0b00010100,
0b00010010,
0b01111111,
0b00001000,

0b00100111, // 5
0b01000101,
0b01000101,
0b01000101,
0b00111001,

0b00111100, // 6
0b01001010,
0b01001001,
0b01001001,
0b00110000,

0b00000001, // 7
0b01110001,
0b00001001,
0b00000101,
0b00000011,

0b00110110, // 8
0b01001001,
0b01001001,
0b01001001,
0b00110110,

0b00000110, // 9
0b01001001,
0b01001001,
0b00101001,
0b00011110,

0b00000000, // Space 11
0b00000000,
0b00000000,
0b00000000,
0b00000000};


write to display:
Code:
void display(Long val)
{
  int i;
  int8 digits[4];
  signed int8 counter;
 
for (counter=3;counter>-1;counter--)
{
    digits[counter]=val%10;
    val=val/10;
}
 
  output_high(rs);
  delay_us(10);
  output_low(rs); 
 
   for(x=0;x<4;x++)
   {   
   for (i=0;i<5;i++)
     {
   delay_us(10);
   write(NUM[digits[x]][i]);
     }
   }
}


I am sure it could be more efficient but it seems to work. It would be nice to have letters too but not needed at the moment.
williefeb_19



Joined: 21 Apr 2008
Posts: 18

View user's profile Send private message

PostPosted: Thu Apr 02, 2009 2:51 am     Reply with quote

It seem like it would be easer if I could get ascii to work. I have been trying to modify the code from the GLCD.C but I can not get it working. Dose anyone have any suggestions.
Code:

char textptr[4]= {'1','2','3','4'};

void print_disp()
{
   int i,j,x; // Loop counters
   BYTE digits[4];                     // Stores character data

   for(i=0; textptr[i] != '\0'; ++i) // Loop through the passed string
   {
      if(textptr[i] < 'S') // Checks if the letter is in the first text array
         memcpy(digits, num[textptr[i]-' '], 5);
      else if(textptr[i] <= '~') // Check if the letter is in the second array
         memcpy(digits, num1[textptr[i]-'S'], 5);
      else
         memcpy(digits, num[0], 5);   // Default to space
   


  output_high(rs);
  delay_us(1);
  write(0b01111111);
  delay_us(1);
  output_low(rs);

  output_high(rs);
  delay_us(1);
  output_low(rs); 
 
     for (x=0;x<5;x++)
     {
      output_high(blank);
      delay_us(1);
      write(digits[i][x]);// Don't know how to increment data for each digit.
      output_low(blank);
    }
 }
}


I have the character all setup in the same kind of arrays. What would be the best way to clock the five sets of data for each character since with this code it is taking them from both arrays?
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