📄 keybord__.c
字号:
/*********************************************
File name : demo_9_3.c
Chip type : ATmega16
Program type : Application
Clock frequency : 4.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*********************************************/
#include <mega16.h>
#include <delay.h>
#include <stdlib.h>
// Standard Input/Output functions
#include <stdio.h>
#define byte unsigned char
int freq_time_counter;
bit freq_time_ok,begin_scan,set_num;
byte freq_point[8];
byte i,fft_cnt=0;
int freq_point_num=1000;
char flag;
char dis_num[5]="";
byte signal_type=0;
void set_dds(int f);
void display_result();
void handle();
#include "head_12864.h"
#include "head_keyboard.h"
#include "head_zimo.h"
#include "head_menu.h"
#include "picture.h"
#include "head_spi.h"
#include "head_FFT.h"
interrupt [TIM0_COMP] void timer0_comp_isr(void)
{
if (++key_stime_counter >=5)
{
key_stime_counter = 0;
key_stime_ok = 1; // 10ms 到
}
if (++freq_time_counter >=500)
{
freq_time_counter=0;
freq_time_ok=1;
}
}
char my_pow(char a,char b);
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
flag=1;
}
void main(void)
{
PORTC=0xFF;
DDRC=0x00;
PORTD=0xFF;
DDRD=0xF3;
KB_PORT = 0xFF; // 键盘接口初始化
KB_DDR = 0xF0; // PD2、PD1、PD0列线,输入方式,上拉有效
SFIOR =0x00;
lcd_init(16);
lcd_clear(); // clere the LCD
/*for (i=0;i<=50;i++)
{
lcd_gotoxy_pic(0,50-i);
disp_picture(picture);
//delay_ms(1);
}//从下往上滚动*/
//disp_picture_disappear(picture);
lcd_clear(); // clere the LCD
last_key=0;
menu_state[0]=0;
set_menu();
set_dds(freq_point_num);
// T/C0 初始化
TCCR0=0x0B; // 内部时钟,64 分频(4M/64=62.5KHz),CTC 模式
TCNT0=0x00;
OCR0=0x7C; // OCR0 = 0x7C(124),(124+1)/62.5=2ms
TIMSK=0x02; // 允许T/C0 比较匹配中断
/*
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Rising Edge
// INT1: Off
// INT2: Off
GICR|=0x40;
MCUCR=0x03;
MCUCSR=0x00;
GIFR=0x40; */
#asm("SEI") // 开放全局中断
while (1)
{
if (key_stime_ok==1)
{
key_stime_ok = 0; // 10ms 到
key_temp = read_keyboard(); // 调用键盘接口函数读键盘
if ((menu_state[0]==2) & (menu_state[1]==21))
set_freq_point();
if ((!set_num)&(!begin_scan)&(key_temp >=1)&(key_temp <=9))
{
if (menu_state[0]==2 & key_temp==2) set_signal_type();
lcd_clear_pic();
select_menu(0,(key_temp-1)*16,16,16);
set_menu();
}
if (menu_state[0]==1)
{
if (fft_cnt==0)
{
//FFT();
lcd_gotoxy(7,2);
handle();
lcd_putchar(dis_num[0]);
lcd_putchar(dis_num[1]);
lcd_putchar(dis_num[2]);
lcd_putchar(dis_num[3]);
display_result();
}
fft_cnt++;
}
if (key_temp!=No_key)
{
last_key=key_temp;
}
}// end of [if (key_stime_ok==1)]
};
}
void set_dds(int f)
{
spi_send_data(f,signal_type);
}
void display_result()
{
int j;
#asm("CLI");
for (i=0;i<N;i++)
{
distortion[i]=i*2;
for (j=0;j<=distortion[i];j++)
{
lcd_putpoint(4*i+2,60-j/2);
lcd_putpoint(4*i+1,60-j/2);
lcd_putpoint(4*i,60-j/2);
}
}
#asm("SEI");
}
void handle()
{
char i;
unsigned int temp;
temp= (char)kf;
for(i=0;i<4;i++)
{
dis_num[3-i]=temp%10+0x30;
temp/=10;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -