|
|
View previous topic :: View next topic |
Author |
Message |
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
Need a sample code to drive a SAA1064 |
Posted: Wed Jan 11, 2006 12:50 pm |
|
|
Did anybody has a library for this chip
and some sample code
Maybe for driving four 7 segment displays
( counting from 1 to 9999 as example) |
|
|
Kenny
Joined: 07 Sep 2003 Posts: 173 Location: Australia
|
|
Posted: Thu Jan 12, 2006 12:59 am |
|
|
This is what I use. There may be a better way to do it.
HTH
Code: |
#include <16F876.h>
#use delay(clock=16000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
#use i2c(master,sda=PIN_C4,scl=PIN_C3,FORCE_HW)
#fuses HS,NOWDT,NOLVP,PUT,NOPROTECT,BROWNOUT
#include "saa1064.h"
int16 count = 0;
void main(void)
{
// Display 'On' on display with SAA1064 ADR pin tied to Vee
send_saa1064_msg(LED_ADDR0,LED_CONTROL,on_);
delay_ms(1000);
send_saa1064_msg(LED_ADDR0,LED_CONTROL,blank_);
delay_ms(300);
while(1)
{
send_saa1064_num(LED_ADDR0,LED_CONTROL,count);
if(++count == 10000) count = 0;
delay_ms(100);
}
}
|
saa1064.h
Code: |
// Driver for SAA1064 i2c to multiplexed four-digit, seven-segment led display
// SAA1064 write addresses set by connecting pin1 (ADR) to different voltages
#define LED_ADDR0 0x70 // ADR to Vee
#define LED_ADDR1 0x72 // ADR to 3/8 Vcc
#define LED_ADDR2 0x74 // ADR to 5/8 Vcc
#define LED_ADDR3 0x76 // ADR to Vcc
// Control bits
// C0 = 0 = static mode C0 = 1 dynamic mode
// C1 = 0/1 digits 1 and 3 are blanked/not blanked
// C2 = 0/1 digits 2 and 4 are blanked/not blanked
// C3 = 1 all segments outputs turned on for segment test
// C4 = 1 adds 3ma to segment output
// C5 = 1 adds 6ma to segment output
// C6 = 1 adds 12ma to segment output
// C7 n/a
#define LED_CONTROL 0x27 //Dynamic mode 6mA
// Segment table (In hex: d.p.=80,g=40,f=20,e=10,d=08,c=04,b=02,a=01)
byte const seg_table[10]=
{0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; // 0,1,2,3,4,5,6,7,8,9
// Some non-numeric characters
//0x00,0x77,0x7C,0x39,0x5E,0x79,0x71,0x36,0x04,0x38, // blank,A,b,C,d,E,F,H,i,L
//0x54,0x5C,0x73,0x50,0x6B,0x1C,0x6E,0x40,0x08 // n,o,p,r,S,u,y,-,_
// Message examples
byte const blank[4] = {0x00,0x00,0x00,0x00};// Blank display
byte const err[4] = {0x00,0x79,0x50,0x50}; // Err
byte const on[4] = {0x00,0x00,0x3F,0x54}; // On
byte const off[4] = {0x00,0x3F,0x71,0x71}; // OFF
enum {blank_,err_,on_,off_};
//--------------------------------------------------------------------------
// Sends number to four-digit led display via SAA1064 (0 to 9999)
void send_saa1064_num(int8 addr,int8 control,int16 num)
{
int8 j; // Digit index
int8 led_data[4]; // Ram array for segment data
int16 temp16;
// Get led segments for all four digits. Don't need to divide to get units.
temp16 = num;
j = 0;
while (j <= 3)
{
if (j != 0) temp16 /= 10;
led_data[j] = seg_table[temp16 %10];
j++;
}
// Do leading zero blanking
if (num<1000) led_data[3] = 0x00;
if (num<100) led_data[2] = 0x00;
if (num<10) led_data[1] = 0x00;
// Add decimal point if required
//led_data[2] |= 0x80;
// Send led segments
i2c_start();
i2c_write(addr); // Send SAA1064 address
i2c_write(0x00); // Send instruction byte. Zero is control reg.
i2c_write(control); // Send control byte
// Auto increment applies for digit data. Have to send out digits in reverse
// because most significant digit is 1st digit.
for (j=4;j>=1;j--)
i2c_write(led_data[j-1] & 0xff);
i2c_stop();
}
//---------------------------------------------------------------------------
//Sends message to led display via SAA1064
void send_saa1064_msg(int8 addr,int8 control,int8 msg)
{
int8 j;
int8 led_data[4]; // Ram array for segments
// Get segments for message.
switch (msg)
{
case blank_:
for(j=0;j<=3;j++)
led_data[j] = blank[j];
break;
case err_:
for(j=0;j<=3;j++)
led_data[j] = err[j];
break;
case on_:
for(j=0;j<=3;j++)
led_data[j] = on[j];
break;
case off_:
for(j=0;j<=3;j++)
led_data[j] = off[j];
break;
default:
for(j=0;j<=3;j++)
led_data[j] = blank[j];
break;
}
// Send led segments
i2c_start();
i2c_write(addr); // Send SAA1064 address
i2c_write(0x00); // Send instruction byte. Zero is control reg.
i2c_write(control); // Send control byte
for (j=0;j<=3;j++)
i2c_write(led_data[j]);
i2c_stop();
}
|
Last edited by Kenny on Sun Jan 15, 2006 8:45 pm; edited 1 time in total |
|
|
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
|
Posted: Thu Jan 12, 2006 3:59 am |
|
|
Thanks, that was what i need |
|
|
JohnLeung
Joined: 18 May 2004 Posts: 15
|
Driving 4 7-segment by PIC itself |
Posted: Sun Jan 15, 2006 10:21 am |
|
|
Hi [spam]
Since you've already got the SAA1064 code, please regard this information as a reference only. I have done similar project in the past, however, since SAA1064 was too difficult to get in my country, so I have tried hard to find alternatives and finally, I am using the PIC itself to do the following:
1. drive 9 7-segment displays by a single PIC 16F877a.
2. Provide DING DONG alert audible tone.
3. Receive and transmit RS232 message to-and-from an operator console.
Please look at the CCS Code library section or take a look at my web page at www.emed-technologies.com. I have put all schematics and source code in there under the PIC section.
John |
|
|
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
|
Posted: Sun Jan 15, 2006 10:25 am |
|
|
Thanks JohnLeung
I have seen it |
|
|
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
|
Posted: Sun Jan 29, 2006 3:17 pm |
|
|
How can i change that routine to display on the first 2 segments the seconds and on the last 2 segment the minutes of a pcf8583
....
void Gettime ()
{
std = read_rtc(0x04)&0x3F; // Stunden vom PCF8583 werden gelesen
min = read_rtc(0x03); // Minuten vom PCF8583 werden gelesen
sek = read_rtc(0x02); // Sekunden vom PCF8583 werden gelesen
zeit[0]=hexd2decD(sek); // Die aktuellen Sekunden werden in den Array gespeichert
zeit[1]=hexd2decD(min); // Die aktuellen Minuten werden in den Array gespeichert
zeit[2]=hexd2decD(std); // Die aktuellen Stunden werden in den Array gespeichert
}
.... |
|
|
|
|
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
|