📄 main.c
字号:
//----------------------------------------------------------------------------
// C main line for Example 3
//
// Copyright 2005, John Hyde, USB DEsign By Example
// You may use this program for development but you may not sell or publish it
// without the written permission of the author
// Send questions to john@USB_By_Example.com
//----------------------------------------------------------------------------
#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
#include "hardware.h"
#include "adcinc.h"
#include "pga.h"
#include "lcd.h"
#include "usb.h"
extern BYTE SOF_Flag;
BYTE Value, Even, Buttons, Count;
BYTE SampleCount, SkipCount;
BYTE H, T, U;
BYTE Voltage, OutReport;
void init_display(void) {
BYTE i;
LCD_Position(0,0);
LCD_PrCString("Temperature =");
LCD_Position(1,0);
LCD_PrCString("Waiting . . . .");
}
void ConvertToDecimal(BYTE Value) {
H = Value/100;
T = (Value - (H*100))/10;
U = (Value - (H*100) - (T*10));
}
void DisplayTemperature(void) {
ConvertToDecimal(Voltage);
LCD_Position(0, 13);
LCD_WriteData(H + '0');
LCD_WriteData(T + '0');
LCD_WriteData(U + '0');
}
void DisplaySampleCount(void) {
ConvertToDecimal(SampleCount);
LCD_Position(1, 0);
LCD_PrCString("Sample = ");
LCD_WriteData(H + '0');
LCD_WriteData(T + '0');
LCD_WriteData(U + '0');
}
void main() {
init_hardware();
M8C_EnableGInt;
// Can now start my ADC
// Note that I had to include a PGA to connect the analog mux to ADC
PGA_Start(3);
ADCINC_Start(3);
ADCINC_GetSamples(1);
LCD_Start();
init_display();
// Connect to the host
USB_Start(0,USB_5V_OPERATION);
// Wait to be enumerated
while (!USB_bGetConfiguration());
USB_INT_REG |= USB_INT_SOF_MASK;
ADCINC_GetSamples(1);
// Post a buffer to wait for a command
USB_EnableOutEP(4);
while(1) {
if (SOF_Flag) {
SOF_Flag = 0;
if (ADCINC_fIsDataAvailable()) {
Voltage = ADCINC_bClearFlagGetData();
DisplayTemperature();
ADCINC_GetSamples(1);
}
// Am I supplying data
if (OutReport) {
// Have I finished supplying data
if (--SkipCount == 0) {
SkipCount = OutReport;
if (SampleCount--) {
// Send another sample
DisplaySampleCount();
USB_LoadInEP(3, &Voltage, 1, USB_TOGGLE);
}
else {
// Finished with these samples, restart
OutReport = 0;
init_display();
}
}
}
// Did I receive a command?
if (USB_bGetEPAckState(4)) {
Count = USB_bReadOutEP(4, &OutReport, 1);
// Setup to supply the samples
SampleCount = 255;
SkipCount = OutReport;
// Wait for another command
USB_EnableOutEP(4);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -