?? enccounter.c
字號:
#include "encoder.h"
#include "uart.h"
#include "rprintf.h"
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <stdlib.h>
#include <avr/wdt.h>
volatile char cmd;
volatile s32 latched;
char temp[100];
void rxRec(unsigned char c)
{
cmd=c;
}
void init(void)
{
uartInit();
encoderInit();
uartInitBuffers();
uartSetBaudRate(9600);
uartSetRxHandler(rxRec);
rprintfInit(uartSendByte);
}
void mydelay(int ms)
{
volatile long harz=0;
while(--ms > 0){
harz=0;
while(harz < 1000)
harz++;
}
}
void print_sample(char cmd)
{
cli();
if(cmd='0')
latched=encoderGetPosition(0);
else
latched=encoderGetPosition(1);
sei();
ltoa(latched,temp,10);
rprintfStr(temp);
rprintfProgStr(PSTR("\r\n"));
}
int main(void)
{
wdt_enable(WDTO_500MS);
init();
rprintfProgStr(PSTR("c: continues \r\n"));
rprintfProgStr(PSTR("0: channel 0 sample \r\n"));
rprintfProgStr(PSTR("other key: channel 1 sample \r\n"));
rprintfProgStr(PSTR("ready:\r\n"));
while(1){
wdt_reset();
if(cmd=='c'){
while(cmd=='c'){
print_sample(cmd);
mydelay(1);
}
}else if(cmd){
print_sample(cmd);
cmd=0;
}
};
return (0);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -