/*----- main.c ------*/
#include "mcc_generated_files/mcc.h"
#include <stdio.h>
#include "USB_1459_CDC.h"
#include "i2cLCD_AQM0802A.h"
#define BFSIZE 32
char NEWLINE[] = "\r\n";
static char rBuf[BFSIZE]; // USB Read Buffer
static char wBuf[BFSIZE]; // USB Write Buffer
int tmFlg; // Timer2 Flag
/*==== Main application ==== */
void main(void)
{
SYSTEM_Initialize(); // initialize the device
INTERRUPT_GlobalInterruptEnable(); // Enable the Global Interrupts
INTERRUPT_PeripheralInterruptEnable(); // Enable the Peripheral Interrupts
int swFlg = 0; // Switch Flag
int adFlg = 0; // ADconvert Flag
int num, i;
int aVal; // AD Converted data
LCD_init();
char msg[] = "Hello!";
LCD_str(msg);
while(USBGetDeviceState() < CONFIGURED_STATE);
SendUSB_str(msg);
SendUSB_str(NEWLINE);
while (1) {
num = RecvUSB(rBuf, BFSIZE);
if(num > 0) {
for(i=0; i < num; i++) {
switch (rBuf[i]) {
case 0x0A:
case 0x0D:
wBuf[i] = 0x00;
break;
default:
wBuf[i] = rBuf[i];
break;
}
}
LCD_clr();
LCD_str(wBuf);
SendUSB_str("PIC> ");
SendUSB_int(num);
SendUSB_str(wBuf);
SendUSB_str(NEWLINE);
if(( rBuf[0] & 0x01) == 0)
LED_SetLow();
else
LED_SetHigh();
}
if((SWC3_GetValue() == 0) & (swFlg == 0)){
swFlg = 1;
if(adFlg == 0){
sprintf(wBuf,"ADC Start");
SendUSB_str(wBuf);
SendUSB_str(NEWLINE);
adFlg = 1;
}else{
sprintf(wBuf,"ADC Hold");
SendUSB_str(wBuf);
SendUSB_str(NEWLINE);
adFlg = 0;
}
}else if((SWC3_GetValue() > 0) & (swFlg == 1)){
swFlg = 0;
}
aVal = ADC_GetConversion(3);
if((tmFlg > 0) & (adFlg > 0)){
sprintf(wBuf,"ADC:%4d",aVal);
LCD_cursor(0,1);
LCD_str(wBuf);
SendUSB_str(wBuf);
SendUSB_str(NEWLINE);
tmFlg = 0;
}
}
}
/******** End of File ******/
|