📄 callback.c
字号:
#include "callback.h"
void key_dec_press_callback()
{
custom_temper++;
check_and_update_digit();
update_taget_impulse();
beep();
}
void key_inc_press_callback()
{
custom_temper--;
check_and_update_digit();
update_taget_impulse();
beep();
}
void red_interrupt_callback()
{
red_int_cnt++;
}
static int state = 0; // 0 wait for a red int, 1 adding, 2 waiting for caculating, 3 controling, 4 tail delaying
static int lost_cnt = 0;
static int tail_delay_cnt = 0;
static int pwm_state = 0;
//volatile int caculation_ok = 0;
//volatile int frame_receive_ok = 0;
//volatile int control_impulse_to_send = 0;
//volatile int impulse_reveived = 0;
static int led_cnt = 0;
static volatile int sound_cnt = 0;
static volatile int sound_type = 0; // 0 alarm, 1 beep;
static int sound = 0;
void timer_4kHz_callback()
{
if (state == 0) { // waiting for a red int;
if (red_int_cnt != 0) {
impulse_reveived = red_int_cnt;
state = 1;
lost_cnt = 0;
red_int_cnt = 0;
synch_lost = 0;
} else {
lost_cnt++;
if ( lost_cnt >4000 ) {
synch_lost = 1;
}
}
} else if (state == 1) { // adding;
if (red_int_cnt == 0) {
lost_cnt++;
if (lost_cnt > 12) {// 3ms
state = 2;
frame_receive_ok = 1;
}
} else {
impulse_reveived += red_int_cnt;
red_int_cnt = 0;
lost_cnt = 0;
}
} else if (state == 2) { // waiting for caculation
if (caculation_ok == 1) {
caculation_ok = 0;
state = 3;
pwm_state = 0;
}
} else if (state == 3) {
if (pwm_state == 0) {
if (control_impulse_to_send > 0) {
control_impulse_to_send--;
set_PWM();
} else {
state = 4;
tail_delay_cnt = 0;
}
} else if (pwm_state == 2) {
del_PWM();
}
if (++pwm_state >= 4) {
pwm_state = 0;
}
} else if ( state == 4 ) {
if (++tail_delay_cnt > 7 ) {
state = 0;
red_int_cnt = 0;
lost_cnt = 0;
}
} else {
/* unkown condition */
while(1);
}
/* deal with led showwing */
if ((++led_cnt & 0x0007) == 0) {
int shift = led_cnt / 8;
int dot;
int num;
if (shift == 1 || shift == 3) {
dot = 1;
} else if (shift == 4 ) {
dot = 0;
shift = 0;
led_cnt = 0;
} else {
dot = 0;
}
if (synch_lost == 1 && (shift <= 1)) {
num = 11;
} else {
num = digit[shift];
}
show_digit(shift, num, dot);
}
/* deal with alarm sound */
if(sound_cnt==0){
if(alarm_enable) {
sound_cnt=1;
sound_type = 0;
}
}
else{
if(sound_cnt>1000){
sound_cnt++;
if(sound_cnt==2000) {
if(alarm_enable) {
sound_type = 0;
sound_cnt=1;
} else {
sound_cnt=0;
}
}
}
else{
sound_cnt++;
if (sound_type == 1) {
sound=sound^0x0fff;
} else {
if ((sound_cnt & 0x0001) == 0) {
sound=sound^0x0fff;
}
}
set_dac(sound);
}
}
/* alarm status */
if (synch_lost == 1 || temper_lost == 1) {
alarm_enable = 1;
} else {
alarm_enable = 0;
}
}
void beep()
{
sound_cnt = 1;
sound_type = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -