Witam,
Mam problem, poniewaz musialam napisac program sygnalizacji swiatel. Dla stop - 8 diod zapalonych, dla go - 8 diod zgaszonych + dla skretu w lewo i prawo. Wiadomo, ze dla stop i go brak petli czasowej, tylko od kilku godzin siedze nad petla do sygnalizacji w lewo i w prawo. Diody maja byc zapalane od prawej do lewej / lewej do prawej. Troche sie zgubilam w kodzie i nie wiem jak zrobic opoznienie dla zapalajacych sie diod. Bylabym wdzieczna za pomoc, kod ponizej:
#include <stdio.h>
/******************* Declare the port addresses **********************/
unsigned char *PORTA = (unsigned char *)0x0000;
unsigned char *DDRA = (unsigned char *)0x0002;
unsigned char *PORTB = (unsigned char *)0x0001;
unsigned char *DDRB = (unsigned char *)0x0003;
unsigned char *PTH = (unsigned char *)0x0260;
unsigned char *DDRH = (unsigned char *)0x0262;
unsigned char *PERH = (unsigned char *)0x0264;
/******************* Light Left ********************************/
unsigned char leftLedPaternTbl[] = { 00000000,
00000001,
00000011,
00000110,
00001100,
00011000,
00110000,
01100000,
11000000,
10000000 };
/******************* Light Right ********************************/
unsigned char rightLedPaternTbl[] = {
00000000,
10000000,
11000000,
01100000,
00110000,
00011000,
00001100,
00000110,
00000011,
00000001 };
unsigned char handleStop(unsigned char x)
{
return 0xff; // all leds should be on
}
unsigned char handleGo(unsigned char x)
{
return 0x00; // all leds should be off;
}
unsigned char handleLeft(unsigned char x)
{
unsigned int index = x % 12; // calc the index for the time
// lookup your partern in array;
return leftLedPaternTbl[index];
}
unsigned char handleRight(unsigned char x)
{
unsigned int index = x % 12; // calc the index for the time
// lookup your partern in array;
return rightLedPaternTbl[index];
}
void main ( void )
{
unsigned char currentState = 0xff;
unsigned char display = 0;
unsigned char time = 0;
unsigned char i;
/******************* Set up I/O ports ********************************/
*DDRH = 0x00;
*PERH = 0xFF;
*DDRA = 0xFF;
*DDRB = 0xFF;
*PORTB = 0xFF;
for ( ; ; )
{
unsigned char sw_data = *PTH & 0x03; // we are only interrested in the lower 2 bits.
*PORTA=display;
if(currentState != sw_data)
{
currentState = sw_data;
}
switch ( currentState )
{
case 0x00: // stop
{
display = handleStop(time);
}
break;
case 0x01: // go
{
display = handleGo(time);
}
break;
case 0x02: // left
{
display = handleLeft(time);
}
break;
case 0x03: // right
{
display = handleRight(time);
}
break;
}
time += 1; // increment time
}
asm("swi");
}