本文整理汇总了C++中USART类的典型用法代码示例。如果您正苦于以下问题:C++ USART类的具体用法?C++ USART怎么用?C++ USART使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了USART类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: GetStateOrder
//监听一个端口,返回一个命令
u8 Transmission::GetStateOrder(USART &ListeningCOM)
{
u8 comand[8]={0};
u8 ch=0;
u8 num = ListeningCOM.ReceiveBufferSize();
if(num>7) //一帧命令包含8个字节
{
ListeningCOM.GetReceivedData(&ch,1);
if(ch == 0xFF)
{
ListeningCOM.GetReceivedData(&ch,1);
if(ch == 0xDD)
{
while(ListeningCOM.ReceiveBufferSize()<6);//等待数据
comand[0]=0xff;
comand[1]=0xDD;
ListeningCOM.GetReceivedData(comand+2,6);
ListeningCOM.ClearReceiveBuffer();
return CommandParsing(comand); //解包
}
else return 0;
}
else
return 0;
}
else
return 0;
}
开发者ID:lissettecarlr,项目名称:HCHO_module,代码行数:29,代码来源:transmission.cpp
示例2: GetWifiNameAndPassword
bool Transmission::GetWifiNameAndPassword(char *name,char *password,USART &ListeningCOM)
{
u8 ch=0;
u8 i =0;
ListeningCOM.GetReceivedData(&ch,1);
if(ch == 0xFF)
{
tskmgr.DelayMs(100);
ListeningCOM.GetReceivedData(&ch,1);
if(ch == 0x03)
{
ListeningCOM.GetReceivedData(&ch,1);
while(ch!=0xff){
*(name+i)=ch;
i++;
ListeningCOM.GetReceivedData(&ch,1);
}
*(name+i)='\0';
ListeningCOM.GetReceivedData(&ch,1);
i=0;
while(ch!=0xff){
*(password+i)=ch;
i++;
ListeningCOM.GetReceivedData(&ch,1);
}
*(password+i)='\0';
return 1;
}
else return 0;
}
else
return 0;
}
开发者ID:lissettecarlr,项目名称:HCHO_module,代码行数:33,代码来源:transmission.cpp
示例3: Run
void Run(uint32_t i2cClockSpeed)
{
bool dmpReady = false; // set true if DMP init was successful
uint8_t mpuIntStatus; // holds actual interrupt status byte from MPU
uint8_t devStatus; // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize; // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount; // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer
Quaternion q; // [w, x, y, z] quaternion container
VectorInt16 aa; // [x, y, z] accel sensor measurements
VectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements
VectorInt16 aaWorld; // [x, y, z] world-frame accel sensor measurements
VectorFloat gravity; // [x, y, z] gravity vector
float eu[3]; // [psi, theta, phi] Euler angle container
float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector
uint16_t y, p, r;
float yaw_offset;
I2C1* i2c = GPIO_Helper::SetupI2C1_PB_6_9(i2cClockSpeed);
i2c->SetErrorHandler(this);
MPU6050 mpu(i2c);
//Initialized with highest sensitivities
mpu.reset();
RCC_Delay_ms(50);
mpu.initialize();
#ifdef USE_USART
uint32_t clockSpeed = 1200000;
USART* usart = GPIO_Helper::SetupUSART2_PA_2_3(clockSpeed);
#endif
devStatus = mpu.dmpInitialize();
if (devStatus != 0)
{
while (1)
;
}
mpu.setDMPEnabled(true);
packetSize = mpu.dmpGetFIFOPacketSize();
while (1)
{
// wait for MPU interrupt or extra packet(s) available
//while (!mpuInterrupt && fifoCount < packetSize) {
//}
// reset interrupt flag and get INT_STATUS byte
mpuIntStatus = mpu.getIntStatus();
// get current FIFO count
fifoCount = mpu.getFIFOCount();
// check for overflow (this should never happen unless our code is too inefficient)
if (mpuIntStatus & 0x02)
{
// wait for correct available data length, should be a VERY short wait
while (fifoCount < packetSize)
fifoCount = mpu.getFIFOCount();
// read a packet from FIFO
mpu.getFIFOBytes(fifoBuffer, packetSize);
// track FIFO count here in case there is > 1 packet available
// (this lets us immediately read more without waiting for an interrupt)
fifoCount -= packetSize;
// display quaternion values in easy matrix form: w x y z
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetEuler(eu, &q);
eu[0] *= 180. / M_PI;
eu[1] *= 180. / M_PI;
eu[2] *= 180. / M_PI;
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
//rad to degrees
ypr[0] *= 180. / M_PI;
ypr[1] *= 180. / M_PI;
ypr[2] *= 180. / M_PI;
// display real acceleration, adjusted to remove gravity
mpu.dmpGetAccel(&aa, fifoBuffer);
mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
// display initial world-frame acceleration, adjusted to remove gravity
// and rotated based on known orientation from quaternion
mpu.dmpGetLinearAccelInWorld(&aaWorld, &aaReal, &q);
#ifdef USE_USART
if (usart->IsRXNE())
{
if (usart->Receive() == 23)
{
usart->SendWord((int16_t)(ypr[0]));
usart->SendWord((int16_t) ypr[1]);
usart->SendWord((int16_t) ypr[2]);
}
}
//.........这里部分代码省略.........
开发者ID:nihuyaka,项目名称:libarmpit-cortex,代码行数:101,代码来源:main.cpp
示例4: spiMaster
void spiMaster() {
// TXEPT is 1 after reset
CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getU0TCTL(), 1));
m->setByte(v->getP1SEL(), 0x31);
m->setByte(v->getU0CTL(), 0); // UCSWRST
// UCTL0 = CHAR + SYNC + MM + SWRST;
m->setByte(v->getU0CTL(), 23);
// UTCTL0 = SSEL1 + SSEL0 + STC;
m->setByte(v->getU0TCTL(), 51);
m->setByte(v->getUC0IE(), 255);
// ME1 |= USPIE0; // Enable USART0 SPI mode
// UCTL0 &= ~SWRST; // Initialize USART state machine
m->setByte(v->getU0ME(), 255);
m->setByte(v->getU0CTL(), 22);
// Set BR
m->setByte(v->getU0BR0(), 2);
// nothing should happen until we send character
CPPUNIT_ASSERT_EQUAL(-1.0, watcher->sclk);
usart->tickRising(); usart->tickFalling();
usart->tickRising(); usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(-1.0, watcher->sclk);
// No transmission, TXEPT is 1
CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getU0TCTL(), 1));
// Set TX IFG just to test it gets cleared by write to TXBUF later
m->setBit(v->getU0IFG(), 128, true);
CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getU0IFG(), 128));
// start transmitting - we will transfer 8 bits
m->setByte(v->getU0TXBUF(), 55); // 00110111
CPPUNIT_ASSERT_EQUAL(-1.0, watcher->sclk);
// Write to TXBUF should clear TX IFG
CPPUNIT_ASSERT_EQUAL(false, m->isBitSet(v->getU0IFG(), 128));
// We are transmitting now, so TXEPT should be 0
CPPUNIT_ASSERT_EQUAL(false, m->isBitSet(v->getU0TCTL(), 1));
// Disable SWRST
m->setBit(v->getU0CTL(), 1, false);
/// BIT 1
// First (MSB) bit should be sent and rising clock generated
usart->tickRising(); usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
CPPUNIT_ASSERT_EQUAL(0.0, watcher->sdo);
// prepare '1' to be captured
pinManager->handlePinInput(0, 3.0);
// bit captured from SOMI
usart->tickRising(); usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);
/// BIT 2
// First (MSB) bit should be sent and rising clock generated
usart->tickRising(); usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
CPPUNIT_ASSERT_EQUAL(0.0, watcher->sdo);
// prepare '0' to be captured
pinManager->handlePinInput(0, 0.0);
// cnt--, bit captured from SDI
usart->tickRising(); usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);
/// BIT 3
// First (MSB) bit should be sent and rising clock generated
usart->tickRising(); usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);
// prepare '0' to be captured
pinManager->handlePinInput(0, 3.0);
// cnt--, bit captured from SDI
usart->tickRising(); usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);
/// BIT 4
// First (MSB) bit should be sent and rising clock generated
usart->tickRising(); usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);
// prepare '0' to be captured
pinManager->handlePinInput(0, 0.0);
// cnt--, bit captured from SDI
usart->tickRising(); usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);
/// BIT 5
// First (MSB) bit should be sent and rising clock generated
usart->tickRising(); usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
CPPUNIT_ASSERT_EQUAL(0.0, watcher->sdo);
//.........这里部分代码省略.........
开发者ID:cybercircuits,项目名称:qsimkit,代码行数:101,代码来源:USART.cpp
示例5:
bool MHZ14::Updata()
{
//向模块发送获取数据
CO2.SendData(Command_getvalue,9);
//判断是否有数据返回
if(CO2.ReceiveBufferSize()<9)
{
CO2.ClearReceiveBuffer(); //清空接收缓存
return false;
}
else
{
CO2.GetReceivedData(rev_buffer,9); //取出一帧数据
CO2.ClearReceiveBuffer(); //清空接收缓存
if(SumCheck(rev_buffer)==false) //校验和
return false;
else
{
DATA_H=rev_buffer[2];
DATA_L=rev_buffer[3];
CO2_Concentration=rev_buffer[2]*256+rev_buffer[3]; //计算浓度
return true;
}
}
}
开发者ID:lissettecarlr,项目名称:RFID-_MAIN,代码行数:27,代码来源:MHZ14.cpp
示例6: main
int main(int argc, char **argv) {
while (true) {
out.print("Enter some text: ");
char buf[20];
out.getline(buf, sizeof(buf));
out.printf("You typed: %s\n", buf);
Task::sleep(1000);
}
}
开发者ID:matthewbot,项目名称:Quadcopter,代码行数:9,代码来源:usarttest.cpp
示例7: docalibrate
static void docalibrate(const char *type, PID::Config *conf) {
out.printf("Old %s: %f %f %f\n", type, conf->p, conf->i, conf->d);
out.printf("New %s PID values:\n", type);
static char buf[100];
out.getline(buf, sizeof(buf));
sscanf(buf, "%f %f %f", &conf->p, &conf->i, &conf->d);
out.printf("Got: %f %f %f\n", conf->p, conf->i, conf->d);
}
开发者ID:matthewbot,项目名称:Quadcopter,代码行数:10,代码来源:motorscontroltest.cpp
示例8: AppInit
void AppInit(void) {
TouchPanelTask.Run();
GUITask.Run();
BlinkTask.Run();
printf("Gib was ein:\r\n");
Serial.ReadLn(buf, 10);
printf("Du hast eingegeben: %s", buf);
}
开发者ID:bonzehan,项目名称:stm32-projects,代码行数:9,代码来源:tasks.cpp
示例9: main
/* ----------------------------------------------------------------------------
* メイン処理
* ---------------------------------------------------------------------------- */
int main(void)
{
setup();
while(1)
{
loop();
Serial1.getrxd();
}
}
开发者ID:ngc6589,项目名称:IN-12bNixieClock,代码行数:12,代码来源:IN-12bNixieClock.cpp
示例10: main
int main(int argc, char **argv) {
out.print("Begin log test!\n");
const uint8_t writedata[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
unsigned int i;
for (i=0;i<20;i++)
logger.write(writedata, sizeof(writedata));
logger.flush();
out.print("Done!\n");
uint8_t data[128];
eeprom.read(EEPROM::pageAddress(0), data, sizeof(data));
out.printf("EEPROM page 0:\n", data);
for (i=0; i<sizeof(data); i++) {
out.printf("%u ", (unsigned int)data[i]);
}
out.print("\n");
}
开发者ID:matthewbot,项目名称:Quadcopter,代码行数:19,代码来源:loggertest.cpp
示例11: main
int main(int argc, char **argv) {
bool prevsynced=true;
while (true) {
Task::sleep(5);
if (vex.getSynced()) {
VexRC::Channels chans = vex.getChannels();
out.printf("%d %d %d %d ", chans.analogs[0], chans.analogs[1], chans.analogs[2], chans.analogs[3]);
out.printf("%s %s\n", digitalToString(chans.left), digitalToString(chans.right));
prevsynced = true;
} else {
if (prevsynced) {
buzzer.buzz(100);
out.print("Not synced\n");
}
prevsynced = false;
}
}
}
开发者ID:matthewbot,项目名称:Quadcopter,代码行数:21,代码来源:vexrctest.cpp
示例12: main
int main(void)
{
char buffer[15];
setup();
for(;;){
ADCSRA |= 1 << ADSC;
loop_until_bit_is_clear(ADCSRA, ADSC);
adch = ADC;
//uart.printstr(str);
itoa(adch, buffer, 10);
uart.printstr( (const char *)buffer );
uart.printstr( "\n" );
_delay_ms(100);
}
return 0;
}
开发者ID:dnivanthaka,项目名称:avr-demos,代码行数:21,代码来源:main.cpp
示例13: loop
/* ----------------------------------------------------------------------------
* メインループ
* ---------------------------------------------------------------------------- */
void loop() {
int i;
int j;
// 1秒毎の処理
if(interruptCount > 999) {
// 時計モード
if(userDataTimerCount == 0) {
rtc.get();
// 年月日表示か時刻表示かの判定
if(displayDateIntervalCount <= displayDateIntervalValue) {
// 時分秒表示
// カンマをクリア
for(int i = 0; i < 8; i++) {
IN12Com[i] = 0;
}
// 6桁フォーマット 999999
if(dispTimeFormat == 0) {
IN12Num[0] = 0x0F;
if(hour12_24format == 1) {
IN12Num[1] = rtc.hourHigh;
IN12Num[2] = rtc.hourLow;
} else {
IN12Num[1] = rtc.hourHigh12;
IN12Num[2] = rtc.hourLow12;
}
IN12Num[3] = rtc.minutesHigh;
IN12Num[4] = rtc.minutesLow;
IN12Num[5] = rtc.secondsHigh;
IN12Num[6] = rtc.secondsLow;
IN12Num[7] = 0x0F;
}
// 8桁フォーマット 99, 99, 99
if(dispTimeFormat == 1) {
if(hour12_24format == 1) {
IN12Num[0] = rtc.hourHigh;
IN12Num[1] = rtc.hourLow;
} else {
IN12Num[0] = rtc.hourHigh12;
IN12Num[1] = rtc.hourLow12;
}
IN12Num[2] = 0x0F;
IN12Num[3] = rtc.minutesHigh;
IN12Num[4] = rtc.minutesLow;
IN12Num[5] = 0x0F;
IN12Num[6] = rtc.secondsHigh;
IN12Num[7] = rtc.secondsLow;
IN12Com[2] = 1;
IN12Com[5] = 1;
}
} else {
// 年月日表示
// カンマクリア
for(int i = 0; i < 8; i++) {
IN12Com[i] = 0;
}
IN12Num[0] = 2;
IN12Num[1] = 0;
IN12Num[2] = rtc.yearHigh;
IN12Num[3] = rtc.yearLow;
IN12Num[4] = rtc.monthHigh;
IN12Num[5] = rtc.monthLow;
IN12Num[6] = rtc.dayHigh;
IN12Num[7] = rtc.dayLow;
if(displayDateIntervalCount >= ( displayDateIntervalValue + displayDateSecondsValue)) {
displayDateIntervalCount = 0;
}
}
displayDateIntervalCount++;
}
// ユーザーデータ表示中
if(userDataTimerCount > 0) {
userDataTimerCount--;
}
// LED 点滅
if(led == false) {
led = true;
PORTC |= (1<<LED);
} else {
led = false;
PORTC &= ~(1<<LED);
}
interruptCount = 0;
}
// シリアル1 受信処理
while(Serial1.available()) {
char ch = Serial1.getch();
serial0String[serial0StringIdx] = ch;
Serial1.putch(ch);
if(serial0String[serial0StringIdx] == '\r') {
Serial1.putch('\n');
serial0String[serial0StringIdx] = 0;
serial0StringComplete = true;
}
serial0StringIdx++;
if(serial0StringIdx >= SERIALBUF_LEN) {
//.........这里部分代码省略.........
开发者ID:ngc6589,项目名称:IN-12bNixieClock,代码行数:101,代码来源:IN-12bNixieClock.cpp
示例14: main
int main()
{
u8 command[6];
u8 datatemp[18];//数据暂存
u8 tagInfo[18];
u8 sensor[16];//保存传感器型号
u8 basic_information[6];//基础信息
u8 version[16];//版本
tskmgr.DelayMs(1000);
tskmgr.DelayMs(1000);
//设置模式
//设置名字密码
//设置IP地址
//复位
WIFI.SendData(CLOSS,6); //关闭回显
tskmgr.DelayMs(1000);
WIFI.SendData(Command1,13); //开启多路连接
tskmgr.DelayMs(1000);
WIFI.SendData(Command2,21); //开启服务器模式
tskmgr.DelayMs(1000);
equipment[0]=2;//测试用 将设备二加入
// DATA_COM.SendData(c,8); //连续发送命令
while(1)
{
//接收从模块数据
if(DATA_COM.ReceiveBufferSize()>=40) //如果接收到了一帧数据
{
u32 check=10,moduleNo;
u8 sum=0;
u8 FFAA=0;
DATA_COM.GetReceivedData(&FFAA,1); //找包头
if(FFAA==0xff)
{
DATA_COM.GetReceivedData(&FFAA,1); //找包头
if(FFAA==0xcc)
{
DATA_COM.GetReceivedData(datatemp,18);
moduleNo=datatemp[0]+datatemp[1]+datatemp[2]+datatemp[3];
for(u8 i=0;i<10;i++) //查询是否有这个设备
{
if(moduleNo==equipment[i])
check=0;//有这个设备
}
for(u8 i=0;i<16;i++)
{
sum+=datatemp[i]; //j校验和
}
sum=sum+0XCB; //加上包头
if(sum==datatemp[17])
check=check+1;
//使用WIFI发送数据给上位机
if(check==1)
{
WIFI.SendData(Command3,17);
tskmgr.DelayMs(100);
WIFI.ClearSendBuffer();
WIFI.SendData(packgroup.MAINToUser(datatemp[5],datatemp[6],datatemp[7],moduleNo,datatemp[4]),20);
tskmgr.DelayMs(100);
WIFI.ClearReceiveBuffer();//清除接收缓存
WIFI.ClearSendBuffer(); //清除发送缓存
}
}
}
}
//从上位机得到命令()
if(WIFI.ReceiveBufferSize()>40)
{
u8 ch=0;
u8 temp_cmd;
u32 temp;
//test
while(WIFI.ReceiveBufferSize()>8)
{
WIFI.GetReceivedData(&ch,1);
if(ch==0xff)//判断包头
{
WIFI.GetReceivedData(&ch,1);
if(ch==0xdd)//判断包头
{
//得到指令
WIFI.GetReceivedData(command,6);
WIFI.ClearReceiveBuffer();
temp_cmd=command[4]; //得到命令位
temp=command[0]+command[1]+command[2]+command[3];//得到设备号
//命令处理
if(temp_cmd==0XAA)//如果命令是注册
{
//读取RFID 将结果给上位机*********************************************
//.........这里部分代码省略.........
开发者ID:lissettecarlr,项目名称:RFID-_MAIN,代码行数:101,代码来源:main.cpp
示例15: main
int main(int argc, char **argv) {
imu.start();
out.printf("Battery: %f cell\n", batmon.getCellVoltage());
out.print("Waiting for remote signal\n");
while (!vex.getSynced()) { Task::sleep(100); }
out.print("Arming\n");
motors.arm();
float heading = imu.getYaw();
buzzer.buzz(300);
while (true) {
control.start();
Logger logger(eeprom, 0);
bool logging = false;
while (true) {
bool up = false;
if (!vex.getSynced()) {
control.stop();
motors.off();
while (!vex.getSynced()) { Task::sleep(100); }
control.start();
sensors.centerGyros();
heading = imu.getYaw();
buzzer.buzz(300);
}
VexRC::Channels chans = vex.getChannels();
if (chans.right != VexRC::NONE)
break;
if (chans.left == VexRC::UP)
logging = true;
else if (chans.left == VexRC::DOWN)
logging = false;
float throttle = chans.analogs[1] / 50.0;
if (throttle < 0)
throttle = 0;
float rollsetpoint = (-chans.analogs[3] / 50.0) * 0.3;
float pitchsetpoint = (-chans.analogs[2] / 50.0) * 0.3;
heading += (chans.analogs[0] / 50.0) * (M_PI / 4) * .005;
control.setControlPoints(throttle, rollsetpoint, pitchsetpoint, heading);
if (!up) {
if (throttle > 0.4)
up = true;
else
control.clearIntegrals();
}
if (logging) {
LogEntry entry = { sensors.getReadings(), imu.getState(), throttle };
logger.write((uint8_t *)&entry, sizeof(entry));
}
IMU::State state = imu.getState();
IMU::State velstate = imu.getVelocityState();
out.printf("%f %f\n", control.getRollCorrection(), control.getPitchCorrection());
Task::sleep(25);
}
control.stop();
motors.off();
out.print("Push enter\n");
while (out.getch() != '\r') { }
out.print("Press y to dump log");
if (out.getch() == 'y') {
out.print("\nLog dump:");
LogReader reader(eeprom, 0);
struct LogEntry entry;
while (reader.read((uint8_t *)&entry, sizeof(entry)) == sizeof(entry)) {
int i;
for (i=0;i<6;i++) {
out.printf("%.3f ", entry.analogs.array[i]);
}
out.printf("%.3f %.3f %.3f ", entry.state.roll, entry.state.pitch, entry.state.yaw);
out.printf("%.3f\n", entry.throttle);
}
}
docalibrate("Roll", &controlconfig.roll_config);
docalibrate("Pitch", &controlconfig.pitch_config);
docalibrate("Yaw", &controlconfig.yaw_config);
out.printf("Current stick values: %f %f\n", controlconfig.rollpitch_stickfactor, controlconfig.yaw_stickfactor);
out.printf("Stick: ");
static char buf[50];
out.getline(buf, sizeof(buf));
sscanf(buf, "%f %f", &controlconfig.rollpitch_stickfactor, &controlconfig.yaw_stickfactor);
}
}
开发者ID:matthewbot,项目名称:Quadcopter,代码行数:95,代码来源:motorscontroltest.cpp
示例16: main
int main(int argc, char **argv) {
out.print("Hello World!\n");
}
开发者ID:matthewbot,项目名称:Quadcopter,代码行数:3,代码来源:helloworld.cpp
示例17: spiSlave
void spiSlave() {
m->setByte(v->getP1SEL(), 0x31);
m->setByte(v->getUCA0CTL1(), 0); // UCSWRST
// UCA0CTL0 |= UCSYNC+UCMSB;
m->setByte(v->getUCA0CTL0(), 33);
// UCA0CTL1 &= ~UCSWRST;
m->setByte(v->getUCA0CTL1(), 0);
// UCA0IE |= UCRXIE | UCTXIE;
m->setByte(v->getUC0IE(), 255);
m->setByte(v->getUCA0TXBUF(), 55); // 00110111
// nothing should happen, because we are slave
CPPUNIT_ASSERT_EQUAL(-1.0, watcher->sclk);
usart->tickRising();
usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(-1.0, watcher->sclk);
// Transfer byte
for (int i = 0; i < 8; ++i) {
pinManager->handlePinInput(1, 3.0);
pinManager->handlePinInput(2, 3.0);
pinManager->handlePinInput(2, 0.0);
CPPUNIT_ASSERT_EQUAL((bool)(55 & (1 << (7 - i))), (bool)watcher->sdo); break;
}
/*
/// BIT 2
// First (MSB) bit should be sent and rising clock generated
usart->tickRising();
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
CPPUNIT_ASSERT_EQUAL(0.0, watcher->sdo);
// prepare '0' to be captured
pinManager->handlePinInput(0, 0.0);
// cnt--, bit captured from SDI
usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);
/// BIT 3
// First (MSB) bit should be sent and rising clock generated
usart->tickRising();
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);
// prepare '0' to be captured
pinManager->handlePinInput(0, 3.0);
// cnt--, bit captured from SDI
usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);
/// BIT 4
// First (MSB) bit should be sent and rising clock generated
usart->tickRising();
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);
// prepare '0' to be captured
pinManager->handlePinInput(0, 0.0);
// cnt--, bit captured from SDI
usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);
/// BIT 5
// First (MSB) bit should be sent and rising clock generated
usart->tickRising();
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
CPPUNIT_ASSERT_EQUAL(0.0, watcher->sdo);
// prepare '0' to be captured
pinManager->handlePinInput(0, 3.0);
// cnt--, bit captured from SDI
usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);
/// BIT 6
// First (MSB) bit should be sent and rising clock generated
usart->tickRising();
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);
// prepare '0' to be captured
pinManager->handlePinInput(0, 0.0);
// cnt--, bit captured from SDI
usart->tickFalling();
CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);
/// BIT 7
// First (MSB) bit should be sent and rising clock generated
usart->tickRising();
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);
// prepare '0' to be captured
pinManager->handlePinInput(0, 3.0);
//.........这里部分代码省略.........
开发者ID:cybercircuits,项目名称:qsimkit,代码行数:101,代码来源:USART.cpp
示例18: setup
/* ----------------------------------------------------------------------------
* セットアップ処理
* ---------------------------------------------------------------------------- */
void setup() {
// Watchdog タイマ停止
MCUSR = 0;
wdt_disable();
// SPI 設定
DDRB |= (1<<PORTB1);
DDRB |= (1<<PORTB2);
// Master 設定
SPCR |= (1<<MSTR);
// ClockDivide 000 = 1/4
SPCR &= ~(1<<SPR1);
SPCR &= ~(1<<SPR0);
SPSR &= ~(1<<SPI2X);
// MODE 0
SPCR &= ~(1<<CPOL);
SPCR &= ~(1<<CPHA);
// MSB First
SPCR &= ~(1<<DORD);
// SPI Enable
SPCR |= (1<<SPE);
// LED ポート出力
DDRC |= (1<<LED);
PORTD = 0;
Serial1.begin();
i2c.begin();
// リセット直後の時間待ち(1秒)
for(int i = 0; i < 100; i++) {
_delay_ms(10);
}
rtc.begin();
// 74HC595
DDRB |= (1<<HC595RCLK);
PORTB &= ~(1<<HC595RCLK);
// K155ID1
DDRB |= (1<<K155ID1_A);
DDRB |= (1<<K155ID1_B);
DDRB |= (1<<K155ID1_C);
DDRB |= (1<<K155ID1_D);
// IN12 カンマ
DDRE |= (1<<COMMA);
// EEPROM 読み出し
eeprom_busy_wait();
displayDateIntervalValue = eeprom_read_word(&E_displayDateIntervalValue);
eeprom_busy_wait();
displayDateSecondsValue = eeprom_read_word(&E_displayDateSecondsValue);
eeprom_busy_wait();
userDataTimerValue = eeprom_read_word(&E_userDataTimerValue);
eeprom_busy_wait();
dispTimeFormat = eeprom_read_byte(&E_dispTimeFormat);
eeprom_busy_wait();
IN12BrightDaytime = eeprom_read_byte(&E_IN12BrightDaytime);
eeprom_busy_wait();
IN12BrightNight = eeprom_read_byte(&E_IN12BrightNight);
eeprom_busy_wait();
hourDaytime = eeprom_read_byte(&E_hourDaytime);
eeprom_busy_wait();
hourNight = eeprom_read_byte(&E_hourNight);
eeprom_busy_wait();
hour12_24format = eeprom_read_byte(&E_hour12_24format);
// タイマー、カウンタ 0 初期化
// Disbale interrupt
TIMSK0 &= ~(1<<OCIE0B);
TIMSK0 &= ~(1<<OCIE0A);
TIMSK0 &= ~(1<<TOIE0);
// 比較一致タイマ/カウンタ解除(CTC)動作
TCCR0B &= ~(1<<WGM02);
TCCR0A |= (1<<WGM01);
TCCR0A &= ~(1<<WGM00);
// clkI/O/64 (64分周)
TCCR0B &= ~(1<<CS02);
TCCR0B |= (1<<CS01);
TCCR0B |= (1<<CS00);
TCNT0 = 0;
// 16MHz / 64 = 4us. 4us * 250 = 1.0ms
OCR0A = 249;
// set interrupt mask
TIFR0 |= (1<<OCF0A);
// Enable interrupt
TIMSK0 |= (1<<OCIE0A);
// Watchdog タイマ設定
wdt_enable(WDTO_1S);
// 割り込み処理を有効にする
sei();
}
开发者ID:ngc6589,项目名称:IN-12bNixieClock,代码行数:100,代码来源:IN-12bNixieClock.cpp
示例19: main
int main(){
u8 order=0;
double record_updataSensor=0;
double record_alive=0;
double record_getwifi=0;
bool network=false ; //网络连接标识位
char *ip = (char*)calloc(15, sizeof(char*) );
char *WifiName = (char*)calloc(20, sizeof(char*) );
char *WifiPassword = (char*)calloc(20, sizeof(char*) );
/*开机WIFI模式选择*****************************************************************/
if(wifimemory.getWifiSum()!=0)//判断表中是否已经保存wifi信息
{
while( wifimemory.Load(WifiName,WifiPassword) )
{
if(wifi.ConnectNetwork_client(WifiName,WifiPassword,SERVER_IP,1111)) //每次连接历时20秒
{network=true; break;}
}
if(network ==false) {
wifi.ConnectNetwork_server(MODULE_COM,0);
WIFI.ClearReceiveBuffer();
}
}
else
{
wifi.ConnectNetwork_server(MODULE_COM,0);
WIFI.ClearReceiveBuffer();
}
Led.SetLevel(1);//将指示灯熄灭(模式切换结束)
/*END*********************************************************************************/
while(1)
{
order=CMCT_Tool.GetStateOrder(WIFI);
switch(order)
{
case DELAY:{}break;
/*启动********************************************************************************************/
case START:{//启动
while(1){
if(tskmgr.ClockTool(record_updataSensor,3)) //每三秒执行一次更新
{
co2.Updata();
if(network)
wifi.Send(20,CMCT_Tool.ToServerPack(CO2Number,co2.DATA_H,co2.DATA_L,0));
else
wifi.Send(0,20,CMCT_Tool.ToClientPack(CO2Number,co2.DATA_H,co2.DATA_L,0));
}
if(CMCT_Tool.GetStateOrder(WIFI)==DELAY)
break;
}
}break;
/*END********************************************************************************************/
/*复位******************************************************************************************/
case RESET:{//复位
wifimemory.ClearAllData(); //清空所有保存信息
*((u32 *)0xE000ED0C) = 0x05fa0004;
}break;
/*END******************************************************************************************/
/*获取WIFI信息*********************************************************************************/
case GETWIFI:{//得到wifi账号密码
record_getwifi=tskmgr.Time();
while(1)
{
if(CMCT_Tool.GetWifiNameAndPassword(WifiName,WifiPassword,WIFI) )
{
//保存WIFI账号密码
com<<WifiName<<"\t"<<WifiPassword<<"\n";
break;
}
if(tskmgr.ClockTool(record_getwifi,30)) //超时10秒退出
break;
}
}break;
/*END******************************************************************************************/
/*模式切换*************************************************************************************/
case MODEL:{//模式切换
wifi.ConnectNetwork_server(MODULE_COM,0);
WIFI.ClearReceiveBuffer();
network=false;
}break;
/*END******************************************************************************************/
/*存活确认*************************************************************************************/
case ALIVE:{//存活确认
if(network)
CMCT_Tool.SendAlive(wifi,CO2Number,1); //存活确认,数据位全为0xff
else
CMCT_Tool.SendAlive(wifi,CO2Number,0);
}break;
/*END******************************************************************************************/
/*常态******************************************************************************************/
default:
{
if(tskmgr.ClockTool(record_updataSensor,3)) //每三秒执行一次更新
//.........这里部分代码省略.........
开发者ID:lissettecarlr,项目名称:CO2_Module,代码行数:101,代码来源:main.cpp
注:本文中的USART类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论