Code
-
Upload
fad24071995 -
Category
Documents
-
view
212 -
download
0
description
Transcript of Code
unsigned char spi(unsigned char data);
void main(void)
{
// Declare your local variables here
unsigned char byte4, byte5, byte6, byte7, byte8, byte9;
unsigned char ID, SS;
unsigned char *tampung;
unsigned char *tampung6;
unsigned char *tampung7;
unsigned char *tampung8;
unsigned char *tampung9;
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=Out Func4=In Func3=Out Func2=Out Func1=In Func0=In
// State7=T State6=T State5=0 State4=T State3=0 State2=0 State1=T State0=T
PORTB=0x04;
DDRB=0x2C;
// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 62.500 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: High
// SPI Data Order: LSB First
SPCR=0x7F;
SPSR=0x00;
// Alphanumeric LCD initialization
// Connections specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTC Bit 0
// RD - PORTC Bit 1
// EN - PORTC Bit 2
// D4 - PORTC Bit 3
// D5 - PORTC Bit 4
// D6 - PORTC Bit 5
// D7 - PORTB Bit 0
// Characters/line: 8
lcd_init(16);
while (1)
{
// Place your code here
lcd_clear();
PORTB.2 = 0;
spi(0x01);
ID = spi(0x42);
SS = spi(0);
byte4 = spi(0);
byte5 = spi(0);
byte6 = spi(0);
byte7 = spi(0);
byte8 = spi(0);
byte9 = spi(0);
PORTB.2 = 1;
lcd_clear();
itoa(ID, tampung);
lcd_gotoxy(0,0);
lcd_puts(tampung);
if (ID == 65)
{
lcd_gotoxy(5,0);
lcd_puts("analog off");
delay_ms(500);
}
else if (ID == 115)
{
lcd_gotoxy(5,0);
lcd_puts("analog on");
delay_ms(500);
}
lcd_clear();
if (byte4 == 0b01111111)
{
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("left");
delay_ms(700);
}
else if (byte4 == 0b10111111)
{
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("down");
delay_ms(700);
}
else if (byte4 == 0b11011111)
{
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("right");
delay_ms(700);
}
else if (byte4 == 0b11101111)
{
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("up");
delay_ms(700);
}
else if (byte4 == 0b11110111)
{
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("start");
delay_ms(700);
}
else if (byte4 == 0b11111110)
{
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("select");
delay_ms(700);
}
else if (byte5 == 0b01111111)
{
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("kotak");
delay_ms(700);
}
else if (byte5 == 0b10111111)
{
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("X");
delay_ms(700);
}
else if (byte5 == 0b11011111)
{
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("bulat");
delay_ms(700);
}
else if (byte5 == 0b11101111)
{
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("segitiga");
delay_ms(700);
}
else if (byte5 == 0b11110111)
{
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("R1");
delay_ms(700);
}
else if (byte5 == 0b11111011)
{
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("L1");
delay_ms(700);
}
else if (byte5 == 0b11111101)
{
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("R2");
delay_ms(700);
}
else if (byte5 == 0b11111110)
{
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("L2");
delay_ms(700);
}
else if ( (ID == 115) && (byte6 == 0b00000000) || (byte6 == 0b11111111) )
{itoa(byte6, tampung6);
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts(tampung6);
lcd_gotoxy(0,5);
lcd_puts(" analog ON");
delay_ms(700);}
else if ( (ID == 115) && (byte7 == 0b00000000) || (byte7 == 0b11111111) )
{itoa(byte7, tampung7);
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts(tampung7);
lcd_gotoxy(0,5);
lcd_puts(" analog ON");
delay_ms(700);}
else if ((ID == 115) && (byte8 == 0b00000000) || (byte8 == 0b11111111) )
{itoa(byte8, tampung8);
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts(tampung8);
lcd_gotoxy(0,5);
lcd_puts(" analog ON");
delay_ms(700);}
else if ((ID == 115) && (byte9 == 0b00000000) || (byte9 == 0b11111111) )
{itoa(byte9, tampung9);
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts(tampung9);
lcd_gotoxy(0,5);
lcd_puts(" analog ON");
delay_ms(700);}
lcd_clear();
}
}