//===============================================
//===============================================
#include <16F628A.h>
#FUSES NOWDT, XT, NOPUT, NOPROTECT, NOBROWNOUT, NOMCLR, NOLVP, NOCPD //628A
#use delay(clock=4000000)
#include <ds1820.c>
#define RTC_SDA PIN_A2
#define RTC_SCL PIN_A3
#use i2c(master, sda=RTC_SDA, scl=RTC_SCL)
BYTE CONST MAP1[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
BYTE CONST MAP2[10]={0xBF,0x86,0xDB,0xCF,0xE6,0xED,0xFD,0x87,0xFF,0xEF};
BYTE buff[DS1820_SCRATCH_BUFFER_SIZE];
BYTE sensor;
BYTE n;
BYTE temp;
BYTE temp_dec;
BYTE sec,min,hour;
BYTE fs_flag;
BYTE RES;
BYTE D_SHIFT;
BYTE Map_Choice;
BYTE ZERO;
#define DEC PIN_B1
#define INC PIN_B2
#define EXP_OUT_CLOCK PIN_B3
#define COLON PIN_B4
#define EXP_OUT_DO PIN_B5
#define EXP_OUT_CLEAR PIN_B6
#define EXP_OUT_LATCH PIN_B7
//========================================
// initial DS1307
//========================================
void init_DS1307()
{
output_float(RTC_SCL);
output_float(RTC_SDA);
}
//========================================
// write data one byte to DS1307
//========================================
void write_DS1307(byte address, BYTE data)
{
short int status;
i2c_start();
i2c_write(0xd0);
i2c_write(address);
i2c_write(data);
i2c_stop();
i2c_start();
status=i2c_write(0xd0);
while(status==1)
{
i2c_start();
status=i2c_write(0xd0);
}
}
//========================================
// read data one byte from DS1307
//========================================
BYTE read_DS1307(byte address)
{
BYTE data;
i2c_start();
i2c_write(0xd0);
i2c_write(address);
i2c_start();
i2c_write(0xd1);
data=i2c_read(0);
i2c_stop();
return(data);
}
//=================================
// WRITE DATA TO 6B595
//=================================
void write_expanded_outputs(BYTE D)
{
BYTE i;
for(i=1;i<=8;++i)
{ // Clock out bits from the eo array
if ((D & 0x80)==0)
output_low(EXP_OUT_DO);
else
output_high(EXP_OUT_DO);
D=D<<1;
output_high(EXP_OUT_CLOCK);
output_low(EXP_OUT_CLOCK);
}
}
//=================================
// show temperature
//=================================
void show_temp()
{
signed int16 Temp16;
int1 TempIsPos;
int8 sensor;
int8 n;
int8 count;
output_low(COLON); // low
for (count=0;count<8;count++) // blink temperature 8 times
{
output_low(EXP_OUT_LATCH);
sensor=0; // DS1820 CONNECT TO PIN A0
init_ds1820(sensor);
write_ds1820_one_byte(0xcc, sensor); // skip ROM
write_ds1820_one_byte(0x44, sensor); // perform temperature conversion
while (read_ds1820_one_byte(sensor)==0xff); // wait for conversion complete
init_ds1820(sensor);
write_ds1820_one_byte(0xcc, sensor); // skip ROM
write_ds1820_one_byte(0xbe, sensor); // read the result
for (n=0; n<DS1820_SCRATCH_BUFFER_SIZE; n++) // read 9 bytes but, use only one byte
{
buff[n]=read_ds1820_one_byte(sensor); // read DS1820
}
Temp16 = make16(buff[1], buff[0]);
if (Temp16 > 0)
{
TempIsPos = TRUE;
Map_Choice = MAP1[RES]; // use normal
ZERO=0x00;
}
else
{
TempIsPos = FALSE;
Temp16 = -Temp16; // Make absolute value
Map_Choice = MAP2[RES]; // show the neg sign
ZERO=0xBF;
}
temp = Temp16 >> 4;
temp_dec = ((Temp16 & 0x0F) * 10) / 16;
// Display data
D_SHIFT=0x00;
write_expanded_outputs(D_SHIFT);
D_SHIFT=(0xD8); // Show 0xD8=°C, 0xF1=°F
write_expanded_outputs(D_SHIFT);
D_SHIFT = MAP2[ temp_dec ]; // Show fraction
write_expanded_outputs(D_SHIFT);
RES = temp%10; // Show 1's
D_SHIFT = MAP1[RES];
write_expanded_outputs(D_SHIFT);
RES=temp/10; // Show 10's
if (RES==0)
D_SHIFT=ZERO;
else
D_SHIFT=Map_Choice;
write_expanded_outputs(D_SHIFT);
output_high(EXP_OUT_LATCH);
delay_ms(500);
output_low(EXP_OUT_LATCH);
for (n=1;n<=4;n++)
{
D_SHIFT=0x00;
write_expanded_outputs(D_SHIFT);
}
output_high(EXP_OUT_LATCH);
delay_ms(500);
}
}
//=================================
// show time 1
//=================================
void show_time1()
{
byte m;
output_low(EXP_OUT_LATCH);
output_low(COLON); // low
min=read_ds1307(1);
hour=read_ds1307(2);
m=min & 0x0F;
D_SHIFT=MAP1[m];
write_expanded_outputs(D_SHIFT);
swap(min);
m=min & 0x07;
D_SHIFT=MAP1[m];
write_expanded_outputs(D_SHIFT);
m=hour & 0x0F;
D_SHIFT=MAP1[m];
write_expanded_outputs(D_SHIFT);
swap(hour);
m=hour & 0x03;
D_SHIFT=MAP1[m];
write_expanded_outputs(D_SHIFT);
output_high(EXP_OUT_LATCH);
swap(min);
swap(hour);
}
//=================================
// check switch
//=================================
void check_sw()
{
byte j;
if (fs_flag!=0)
{
if (!input(INC))
{
if (fs_flag==1)
{
min=read_ds1307(1);
min++;
j=min & 0x0F;
if (j>=0x0A) min=min+0x06;
if (min>=0x60) min=0;
write_ds1307(1,min);
}
else
{
hour=read_ds1307(2);
hour++;
j=hour & 0x0F;
if (j>=0x0A) hour=hour+0x06;
if (hour>=0x24) hour=0;
write_ds1307(2,hour);
}
show_time1();
}
if (!input(DEC))
{
if (fs_flag==1)
{
min=read_ds1307(1);
if (min!=0)
{
min--;
j=min & 0x0F;
if (j>=0x0A) min=min-0x06;
}
else min=0x59;
write_ds1307(1,min);
}
else
{
hour=read_ds1307(2);
if (hour!=0)
{
hour--;
j=hour & 0x0F;
if (j>=0x0A) hour=hour-0x06;
}
else hour=0x23;
write_ds1307(2,hour);
}
show_time1();
}
}
}
//=================================
// show time
//=================================
void show_time(byte fs)
{
byte m;
output_low(EXP_OUT_LATCH);
output_high(COLON); // high
min=read_ds1307(1);
hour=read_ds1307(2);
m=min & 0x0F;
D_SHIFT=MAP1[m];
write_expanded_outputs(D_SHIFT);
swap(min);
m=min & 0x07;
D_SHIFT=MAP1[m];
write_expanded_outputs(D_SHIFT);
m=hour & 0x0F;
D_SHIFT=MAP1[m];
write_expanded_outputs(D_SHIFT);
swap(hour);
m=hour & 0x03;
D_SHIFT=MAP1[m];
write_expanded_outputs(D_SHIFT);
output_high(EXP_OUT_LATCH);
swap(min);
swap(hour);
delay_ms(100);
check_sw();
delay_ms(100);
check_sw();
delay_ms(100);
check_sw();
delay_ms(100);
check_sw();
delay_ms(100);
check_sw();
if (fs==0)
{
output_low(COLON);
}
else
{
if (fs==1)
{
output_high(COLON); // high
output_low(EXP_OUT_LATCH);
D_SHIFT=0x00;
write_expanded_outputs(D_SHIFT);
D_SHIFT=0x00;
write_expanded_outputs(D_SHIFT);
m=hour & 0x0F;
D_SHIFT=MAP1[m];
write_expanded_outputs(D_SHIFT);
swap(hour);
m=hour & 0x03;
D_SHIFT=MAP1[m];
write_expanded_outputs(D_SHIFT);
output_high(EXP_OUT_LATCH);
}
else
{
output_high(COLON);// high
output_low(EXP_OUT_LATCH);
m=min & 0x0F;
D_SHIFT=MAP1[m];
write_expanded_outputs(D_SHIFT);
swap(min);
m=min & 0x07;
D_SHIFT=MAP1[m];
write_expanded_outputs(D_SHIFT);
D_SHIFT=0x00;
write_expanded_outputs(D_SHIFT);
D_SHIFT=0x00;
write_expanded_outputs(D_SHIFT);
output_high(EXP_OUT_LATCH);
}
}
delay_ms(100);
check_sw();
delay_ms(100);
check_sw();
delay_ms(100);
check_sw();
delay_ms(100);
check_sw();
delay_ms(100);
check_sw();
}
#int_EXT
void EXT_isr()
{
fs_flag++;
if (fs_flag>=3) fs_flag=0;
}
//=====================================
// main program start here
//=====================================
void main(void)
{
byte u;
delay_ms(100);
port_b_pullups(true);
output_low(EXP_OUT_CLEAR);
delay_us(10); //was 10
output_high(EXP_OUT_CLEAR);
init_ds1307();
u=read_ds1307(0);
sec=u & 0x7F;// enable RTC
write_ds1307(0,sec); // set second to 00 and enable clock(bit7=0)
output_low(EXP_OUT_CLOCK);
fs_flag=0;
ext_int_edge(H_TO_L); // init interrupt triggering for button press
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(true)
{
disable_interrupts(INT_EXT);
if (fs_flag==0)
{
show_temp();
}
enable_interrupts(INT_EXT);
for (u=0;u<20;u++)
{
show_time(fs_flag);
}
}
} //end of main program
//=====================================
// main program start here
//=====================================
void main(void)
{
byte u;
delay_ms(100);
port_b_pullups(true);
output_low(EXP_OUT_CLEAR);
delay_us(10); //was 10
output_high(EXP_OUT_CLEAR);
//try shifting to all Zero's here
{
D_SHIFT=0x00;
write_expanded_outputs(D_SHIFT);
D_SHIFT=(0x3F);
write_expanded_outputs(D_SHIFT);
D_SHIFT=(0x3F);
write_expanded_outputs(D_SHIFT);
D_SHIFT=(0x3F);
write_expanded_outputs(D_SHIFT);
D_SHIFT=(0x3F);
write_expanded_outputs(D_SHIFT);
output_high(EXP_OUT_LATCH);
delay_ms(500);
output_low(EXP_OUT_LATCH);
for (n=1;n<=4;n++)
{
D_SHIFT=0x00;
write_expanded_outputs(D_SHIFT);
}
output_high(EXP_OUT_LATCH);
delay_ms(500);
}
//ends shifting routine at startup
init_ds1307();
u=read_ds1307(0);
sec=u & 0x7F;// enable RTC
write_ds1307(0,sec); // set second to 00 and enable clock(bit7=0)
output_low(EXP_OUT_CLOCK);
fs_flag=0;
ext_int_edge(H_TO_L); // init interrupt triggering for button press
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(true)
{
disable_interrupts(INT_EXT);
if (fs_flag==0)
{
show_temp();
}
enable_interrupts(INT_EXT);
for (u=0;u<20;u++)
{
show_time(fs_flag);
}
}
} //end of main program
The MAX6969 looks promising for the scrolling matrix. The only thing is its has 16 Constant-Current LED Outputs meaning you are going to need quiet a few to get a large display like that. the A6279 is really similar to the MAX6969.
Im not sure but i might consider getting " MAX6955 " for the matrix project.
Specs:
# 400kbps 2-Wire I²C-Compatible Interface
# 2.7V to 5.5V Operation
# Drives Up to 16 Digits 7-Segment, 8 Digits 14-Segment, 8 Digits 16-Segment, 128 Discrete LEDs, or a Combination of Digit Types
# Drives Common-Cathode Monocolor and Bicolor LED Displays
# Built-In ASCII 104-Character Font for 14-Segment and 16-Segment Digits and Hexadecimal Font for 7-Segment Digits
That looks like a keeper!
Here's the only problem(s) I see with the 6955:Im not sure but i might consider getting " MAX6955 " for the matrix project.
Specs:
# 400kbps 2-Wire I²C-Compatible Interface
# 2.7V to 5.5V Operation
# Drives Up to 16 Digits 7-Segment, 8 Digits 14-Segment, 8 Digits 16-Segment, 128 Discrete LEDs, or a Combination of Digit Types
# Drives Common-Cathode Monocolor and Bicolor LED Displays
# Built-In ASCII 104-Character Font for 14-Segment and 16-Segment Digits and Hexadecimal Font for 7-Segment Digits
That looks like a keeper!
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?