00001
00189 #include <avr/io.h>
00190 #include <avr/interrupt.h>
00191 #include <avr/wdt.h>
00192 #include <util/delay.h>
00193 #include <avr/pgmspace.h>
00194
00195 #include "twislave.h"
00196
00200 void init_ports(void){
00201
00202 DDRB = 0xff;
00203 DDRC |= (1 << PINC0) | (1 << PINC1);
00204
00205 PORTB = 0x00;
00206 PORTC &= ~((1 << PINC0) | (1 << PINC1));
00207
00208 DDRD = 0x00;
00209 PORTD = 0x00;
00210 }
00211
00216 void selectDigit(uint8_t digit) {
00217 switch (digit) {
00218 case 0:
00219 case 1:
00220 case 2:
00221 case 3:
00222 case 4:
00223 case 5:
00224 PORTB = (1 << digit);
00225 PORTC &= ~((1 << PINC0) | (1 << PINC1));
00226 break;
00227 case 6:
00228 PORTB = 0x00;
00229 PORTC &= ~((1 << PINC1));
00230 PORTC |= (1 << PINC0);
00231 break;
00232 case 7:
00233 PORTB = 0x00;
00234 PORTC &= ~((1 << PINC0));
00235 PORTC |= (1 << PINC1);
00236 break;
00237 default:
00238 PORTB = 0x00;
00239 PORTC = 0x00;
00240 }
00241 }
00242
00247 void showByte(uint8_t byte) {
00248 DDRD = byte;
00249 }
00250
00258 void showDigitByte(uint8_t digit, uint8_t byte) {
00259 showByte(0x00);
00260 selectDigit(digit);
00261 showByte(byte);
00262 }
00263
00271 int main(void) {
00272
00273 init_ports();
00274
00275
00276 wdt_enable(WDTO_15MS);
00277
00278
00279 init_twi_slave(0x10);
00280
00281 while (1) {
00282 wdt_reset();
00283 for (uint8_t digit = 0; digit <= 7; digit++) {
00284
00285 showDigitByte(digit, rxbuffer[digit]);
00286 }
00287 }
00288 return 0;
00289 }