//----------------------------------------------------------------------------
//
// Switch S1 is connected to P0.2 (Down=Start Movement/Up=Stop Movement)
// Switch S2 is connected to P0.3 (Down=Left Button Down/Up=Left Button Up)
// Switch S3 is connected to P0.4 (Not used)
//
// LED D1 is connected to P0.5 (Tracks S1: On=Down/Off=Up)
// LED D2 is connected to P0.6 (Tracks S2: On=Down/Off=Up)
// LED D3 is connected to P1.3 (Not used)
//
//----------------------------------------------------------------------------
#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
// Constant for button handling
#define GO 1
#define STOP 0
#define UP 0
#define DOWN 1
// Constants for the mouse reports
#define STEP_SIZE 1
#define X_SIGN (1)
#define Y_SIGN (1)
#define LB_DOWN 1
#define LB_UP 0
// Movement Vectors for the letters U, S, and B
#define STEP(b,y,x) ( b ), \
(unsigned char)((Y_SIGN)*(y)*(STEP_SIZE)),(unsigned char)((X_SIGN)*(x)*(STEP_SIZE)),0
const BYTE a_logo_vectors[] =
{
STEP(LB_DOWN, 0x00, 0x00), // ;1
STEP(LB_DOWN, 0x00, 0x05), // ;1
STEP(LB_DOWN, 0x00, 0x05), // ;2
STEP(LB_DOWN, 0x00, 0x05), // ;3
STEP(LB_DOWN, 0x00, 0x05), // ;4
STEP(LB_DOWN, 0x00, 0x05), // ;5
STEP(LB_DOWN, 0x05, 0x05), // ;6
STEP(LB_DOWN, 0x05, 0x00), // ;7
STEP(LB_DOWN, 0x05, 0x00), // ;8
STEP(LB_DOWN, 0x05, 0xFB), // ;9
STEP(LB_DOWN, 0x00, 0xFB), // ;10
STEP(LB_DOWN, 0x00, 0xFB), // ;11
STEP(LB_DOWN, 0x00, 0xFB), // ;12
STEP(LB_DOWN, 0x00, 0xFB), // ;13
STEP(LB_UP, 0x00, 0xFB), // ;14 End of 'U'
STEP(LB_DOWN, 0x23, 0x05), // ;15
STEP(LB_DOWN, 0xFB, 0xFB), // ;16
STEP(LB_DOWN, 0xFB, 0x00), // ;17
STEP(LB_DOWN, 0xFB, 0x00), // ;18
STEP(LB_DOWN, 0xFB, 0x05), // ;19
STEP(LB_DOWN, 0x00, 0x05), // ;20
STEP(LB_DOWN, 0x05, 0x05), // ;21
STEP(LB_DOWN, 0x05, 0x00), // ;22
STEP(LB_DOWN, 0x05, 0x00), // ;23
STEP(LB_DOWN, 0x05, 0x05), // ;24
STEP(LB_DOWN, 0x00, 0x05), // ;25
STEP(LB_DOWN, 0xFB, 0x05), // ;26
STEP(LB_DOWN, 0xFB, 0x00), // ;27
STEP(LB_DOWN, 0xFB, 0x00), // ;28
STEP(LB_DOWN, 0xFB, 0xFB), // ;29
STEP(LB_UP, 0x05, 0x05), // ;30
STEP(LB_DOWN, 0x1E, 0x00), // ;31
STEP(LB_DOWN, 0x05, 0x00), // ;32
STEP(LB_DOWN, 0x05, 0x00), // ;33
STEP(LB_DOWN, 0x05, 0x00), // ;34
STEP(LB_DOWN, 0x05, 0xFB), // ;35
STEP(LB_DOWN, 0x00, 0xFB), // ;36
STEP(LB_DOWN, 0xFB, 0xFB), // ;37
STEP(LB_DOWN, 0xFB, 0x00), // ;38
STEP(LB_DOWN, 0xFB, 0x00), // ;39
STEP(LB_DOWN, 0xFB, 0x00), // ;40
STEP(LB_DOWN, 0x0F, 0x00), // ;41
STEP(LB_DOWN, 0x05, 0xFB), // ;42
STEP(LB_DOWN, 0x00, 0xFB), // ;43
STEP(LB_DOWN, 0xFB, 0xFB), // ;44
STEP(LB_DOWN, 0xFB, 0x00), // ;45
STEP(LB_DOWN, 0xFB, 0x00), // ;46
STEP(LB_DOWN, 0xFB, 0x00), // ;47
STEP(LB_DOWN, 0x00, 0x05), // ;48
STEP(LB_DOWN, 0x00, 0x05), // ;49
STEP(LB_DOWN, 0x00, 0x05), // ;50
STEP(LB_DOWN, 0x00, 0x05), // ;51
STEP(LB_DOWN, 0x00, 0x05), // ;52
STEP(LB_DOWN, 0x00, 0x05), // ;53
STEP(LB_UP, 0x00, 0xE2), // ;54
STEP(LB_UP, 0xBA, 0x00), // ;55
STEP(LB_UP, 0x00, 0x00) // ;56
};
//
BYTE left_button;
BYTE move;
BYTE a_ram[4];
const unsigned char *p_data;
void main()
{
USB_Start(0); // Enable USB
M8C_EnableGInt; // and Global Interrupts
while (USB_bGetConfiguration() == 0) // Wait for USB enumeration
{}
p_data = &a_logo_vectors[0]; // Point to the first of the logo vectors
move = STOP;
left_button = UP;
while (1)
{
move = ((P0DATA & 0x04) ? STOP : GO); // P0.2 Up or Down
left_button = ((P0DATA & 0x08) ? UP : DOWN); // P0.3 Up or Down
if (move == STOP)
P0DATA |= 0x20; // P0.5 high (off)
else
P0DATA &= ~(0x20); // P0.5 low (on)
if (left_button == UP)
P0DATA |= 0x40; // P0.6 high (off)
else
P0DATA &= ~(0x40); // P0.6 low (on)
if (move == GO)
{
// Check to see if the endpoint is empty
if (USB_bGetEPState(1) == IN_BUFFER_EMPTY)
{
a_ram[0] = ((left_button == DOWN) ? *p_data : *p_data & ~(LB_DOWN));
p_data++;
a_ram[1] = *p_data; p_data++;
a_ram[2] = *p_data; p_data++;
a_ram[3] = *p_data; p_data++;
if (p_data > &a_logo_vectors[sizeof(a_logo_vectors) - 1])
p_data = &a_logo_vectors[0];
USB_LoadEP(1, &a_ram[0], 3);
}
}
}
}
评论0