📄 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 + -