So weit so gut.... der mega8 kann die anzeige perfekt steuern, hier code:
Code:
#include <avr/io.h>
#include "i2cmaster.h"
#include <util/delay.h>
#define pcf 0b01000110 // Anzeige
#define pcf2 0b01000010 // Segmente
void long_delay(uint16_t ms){
for(; ms>0; ms--) _delay_ms(1);
}
const char Zahl[] = {
0b01000100,
0b01111101,
0b10100100,
0b00110100,
0b00011101,
0b00010110,
0b00000110,
0b01111100,
0b00000100,
0b00010100
};
void twi_send( unsigned char befehl ){
i2c_start(pcf+I2C_WRITE);
i2c_write(befehl);
i2c_stop();
}
void twi_send2( unsigned char befehl1 ){
i2c_start(pcf2+I2C_WRITE);
i2c_write(befehl1);
i2c_stop();
}
void ZeigeZahl(uint16_t Zahl4){
char a_zahl1[5];
snprintf(a_zahl1, sizeof(a_zahl1), "%d", Zahl4);
twi_send(0b1111110);
twi_send2(Zahl[a_zahl1[0] - '0']);
long_delay(8);
twi_send2(0b11111111);
twi_send(0b1111101);
twi_send2(Zahl[a_zahl1[1] - '0']);
long_delay(8);
twi_send2(0b11111111);
twi_send(0b1111011);
twi_send2(Zahl[a_zahl1[2] - '0']);
long_delay(8);
twi_send2(0b11111111);
twi_send(0b1110111);
twi_send2(Zahl[a_zahl1[3] - '0']);
long_delay(8);
twi_send2(0b11111111);
}
int main(void)
{
i2c_init();
while(1)
{
ZeigeZahl(1234);
}
return 0;
}
So, aber wie kann die M32 dem mega8 jetzt sagen, was er zeigen soll?
edit:
habe die plantine verkleinert, damit ich sie unter der normalen exp. verstecken kann.
hier noch ein (handy-) Foto: (habe meine richte cam gerade nicht hier)
Lesezeichen