Zur Zeit gibts es nur Fortschritte in homöopathischen Dosen.
Ich habe meine get_time-Funktionen erweitert um aus dem BCD-Code eine "normale" Zahl zu erzeugen:
Code:
unsigned char get_time_s()
{
i2c_start_wait(DS1307+I2C_WRITE);
i2c_write(0x00);
i2c_stop();
i2c_start(DS1307+I2C_READ);
time_s = i2c_readNak();
i2c_stop();
einer=time_s;
einer&= 0x0f;
zehner=time_s;
zehner=zehner>>4;
zehner&= 0x07;
time_s = einer+10*zehner;
return time_s;
}
Diese lässt sich auch auf dem LCD-Display ausgeben:
Code:
sprintf(buffer, "%i",time_s);
lcd_puts(buffer);
Allerdings kann ich damit keine Switch-Anweisung füttern. Bei
Code:
switch(time_s)
{
case 0: COLUMN = (1<<C1);
ROW = ~(1<<R1);
break;
case 2: COLUMN = (1<<C2);
ROW = ~(1<<R1);
break;
case 4: COLUMN = (1<<C3);
ROW = ~(1<<R1);
break;
case 6: COLUMN = (1<<C4);
ROW = ~(1<<R1);
break;
......
springt er immer in das case 0 -Ergebnis.
Hier noch der komplette Code
Code:
//***Included Files**//
#include "i2cmaster/i2cmaster.h"
#include <util/delay.h>
#include <stdio.h>
#include <avr/io.h>
#include <stdlib.h>
//***Defines***//
#define DS1307 0xD0
#define R1 PD0
#define R2 PD1
#define R3 PD3
#define R4 PD4
#define R5 PD2
#define C1 PB0
#define C2 PB1
#define C3 PB2
#define C4 PB3
#define C5 PB4
#define COLUMN PORTB
#define ROW PORTD
unsigned char time_s;
unsigned char time_m;
unsigned char time_h;
unsigned char zehner;
unsigned char einer;
int test;
unsigned char buffer[10];
//***Functions***//
unsigned char set_clock(unsigned char reg, unsigned char val)
{
if (i2c_start(DS1307+I2C_WRITE) != 0) return 1;
i2c_write(reg);
i2c_write(val);
i2c_stop();
return 0;
}
unsigned char get_time_s()
{
i2c_start_wait(DS1307+I2C_WRITE);
i2c_write(0x00);
i2c_stop();
i2c_start(DS1307+I2C_READ);
time_s = i2c_readNak();
i2c_stop();
einer=time_s;
einer&= 0x0f;
zehner=time_s;
zehner=zehner>>4;
zehner&= 0x07;
time_s = einer+10*zehner;
return time_s;
}
unsigned char get_time_m()
{
i2c_start_wait(DS1307+I2C_WRITE);
i2c_write(0x01);
i2c_stop();
i2c_start(DS1307+I2C_READ);
time_m = i2c_readNak();
i2c_stop();
einer=time_m;
einer&= 0x0f;
zehner=time_m;
zehner=zehner>>4;
zehner&= 0x07;
time_m = einer+10*zehner;
return time_m;
}
unsigned char get_time_h()
{
i2c_start_wait(DS1307+I2C_WRITE);
i2c_write(0x02);
i2c_stop();
i2c_start(DS1307+I2C_READ);
time_h = i2c_readNak();
i2c_stop();
einer=time_h;
einer&= 0x0f;
zehner=time_h;
zehner=zehner>>4;
zehner&= 0x07;
time_h = einer+10*zehner;
return time_h;
}
//***Mainfunction***//
int main (void)
{
//***Initilize I/O***//
DDRB = (1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB3)|(1<<PB4); // PB0 to PB4 as Output (Columns)
DDRD = (1<<PD0)|(1<<PD1)|(1<<PD2)|(1<<PD3)|(1<<PD4); // PD0 to PD4 as Output (Rows)
//set_time(0x00, 0x17);
//set_time(0x01, 0x24);
//set_time(0x02, 0x20);
while (1)
{
get_time_s();
// get_time_m();
test = time_s;
switch(time_s)
{
case 0: COLUMN = (1<<C1);
ROW = ~(1<<R1);
break;
case 2: COLUMN = (1<<C2);
ROW = ~(1<<R1);
break;
case 4: COLUMN = (1<<C3);
ROW = ~(1<<R1);
break;
case 6: COLUMN = (1<<C4);
ROW = ~(1<<R1);
break;
case 8: COLUMN = (1<<C5);
ROW = ~(1<<R1);
break;
case 10: COLUMN = (1<<C1);
ROW = ~(1<<R2);
break;
case 12: COLUMN = (1<<C2);
ROW = ~(1<<R2);
break;
case 14: COLUMN = (1<<C3);
ROW = ~(1<<R2);
break;
case 16: COLUMN = (1<<C4);
ROW = ~(1<<R2);
break;
case 18: COLUMN = (1<<C5);
ROW = ~(1<<R2);
break;
case 20: COLUMN = (1<<C1);
ROW = ~(1<<R3);
break;
case 22: COLUMN = (1<<C2);
ROW = ~(1<<R3);
break;
case 24: COLUMN = (1<<C3);
ROW = ~(1<<R3);
break;
case 26: COLUMN = (1<<C4);
ROW = ~(1<<R3);
break;
case 28: COLUMN = (1<<C5);
ROW = ~(1<<R3);
break;
case 30: COLUMN = (1<<C1);
ROW = ~(1<<R4);
break;
case 32: COLUMN = (1<<C2);
ROW = ~(1<<R4);
break;
case 34: COLUMN = (1<<C3);
ROW = ~(1<<R4);
break;
case 36: COLUMN = (1<<C4);
ROW = ~(1<<R4);
break;
case 38: COLUMN = (1<<C5);
ROW = ~(1<<R4);
break;
case 40: COLUMN = (1<<C1);
ROW = ~(1<<R5);
break;
case 42: COLUMN = (1<<C2);
ROW = ~(1<<R5);
break;
case 44: COLUMN = (1<<C3);
ROW = ~(1<<R5);
break;
case 46: COLUMN = (1<<C4);
ROW = ~(1<<R5);
break;
case 48: COLUMN = (1<<C5);
ROW = ~(1<<R5);
break;
case 50: COLUMN = (1<<C1)|(1<<C2);
ROW = ~(1<<R1);
break;
case 52: COLUMN = (1<<C1)|(1<<C2);
ROW = ~(1<<R2);
break;
case 54: COLUMN = (1<<C1)|(1<<C2);
ROW = ~(1<<R3);
break;
case 56: COLUMN = (1<<C1)|(1<<C2);
ROW = ~(1<<R4);
break;
case 58: COLUMN = (1<<C1)|(1<<C2);
ROW = ~(1<<R5);
break;
case 60: COLUMN = (1<<C1)|(1<<C3);
ROW = ~(1<<R1);
break;
case 255: COLUMN = (1<<C1)|(1<<C3);
ROW = ~(1<<R1)|~(1<<R5);
break;
}
}
return 0;
}
Lesezeichen