单片机的按键种类
基于Megae16单片机 -【Leep_H】
AD按键
利用AD按键是利用不同的电压大小区分相对应的按键,优点呢节省io口,但是缺点也很明显,一旦电路负载的开关过多,期间的差值就很小,分辨不出。主要用于电视机的按键,MP3,MP4等等。
本电路图如下
代码如下:
/*********************************************
File name : 7seg.c
Chip type : ATmega16
Program type : Application
Clock frequency : 4.000000 MHz
Memory model : Small
External SRAM size : 0
*********************************************/
#include <iom16v.h>
#include <macros.h>
#define CLR_SHCLK() PORTB&=~(1<<1) //移位时钟 SCLK
#define SET_SHCLK() PORTB|=(1<<1) //移位时钟 SCLK,上升沿
#define CLR_STCLK() PORTB&=~(1<<0) //锁存时钟 RCLK
#define SET_STCLK() PORTB|=(1<<0) //拉高锁存时钟,上升沿
#define CLR_DS() PORTA&=~(1<<0) //清零
#define SET_DS() PORTA|=(1<<0) //置位
#define U8 unsigned char
unsigned char led_7[16] ={
0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
int disp_buff[4]={
0,0,0,0};
int count=0,time_100=0;
float adcread;
int adcc,flag;
int a;int b;
static int readi=0;
unsigned char posit = 0;
void adc_init(void)
{
ADMUX=0X67;
ADCSR=0X87;
}
void Hc595send(unsigned char SndData)
{
U8 i;
for(i=0;i<8;i++)
{
if(SndData&(1<<(7-i))){
SET_DS();
}else{
CLR_DS();
}
CLR_SHCLK(); //移位时钟 SCLK
SET_SHCLK(); //移位时钟 SCLK,上升沿
}
CLR_STCLK();
SET_STCLK(); //拉高锁存时钟,上升沿
}
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x01;
PORTB = 0x00;
DDRB = 0x03;
PORTC = 0x00; /