#include "mbed.h"
#include "device.h"
DigitalIn mybutton(USER_BUTTON);
DigitalOut myled(LED1);
DigitalOut myBZ(D0);
DigitalOut AB(D6);
DigitalOut CP(D7);
BusOut myLEDcom(A0,A1,A2,A3,A4,A5);
unsigned char LED_mode;
unsigned char LEDdata;
void Transmit_SN74H164(unsigned char Data)
{
unsigned char i;
for(i=0;i<8;i++)
{
CP=0;
// _nop_();
wait_us(1);
// AB=(bit)(Data&0x80);
if(Data&0x80){AB=1;}else{AB=0;}
// _nop_();
wait_us(1);
CP=1;
// _nop_();
wait_us(1);
Data<<=1;
}
}
int main() {
// unsigned char LED_mode;
// unsigned char LEDdata;
myLEDcom=0xff;
while(1) {
if (mybutton == 0) { // Button is pressed
myled = !myled; // Toggle the LED state
myBZ = !myBZ;
LED_mode++;
if(LED_mode>9)LED_mode=0;
switch(LED_mode)
{
case 0: LEDdata=0xc0; break;
case 1: LEDdata=0xf9; break;
case 2: LEDdata=0xa4; break;
case 3: LEDdata=0xb0; break;
case 4: LEDdata=0x99; break;
case 5: LEDdata=0x92; break;
case 6: LEDdata=0x82; break;
case 7: LEDdata=0xf8; break;
case 8: LEDdata=0x80; break;
case 9: LEDdata=0x90; break;
}
// wait(0.2); // 200 ms
myLEDcom=0xff;
Transmit_SN74H164(LEDdata);
myLEDcom=0xfe;
wait(0.2); // 200 ms
}
}
}