|
' 你好,我能试一下您的程序吗?我有好多旧的450,谢谢,73。
' 程序挺乱,是在我自己开发板上试的,你可以参考一下。 - #include <avr/io.h>
- #include <util/delay.h>
- #include <avr/pgmspace.h>
- #include <compat/ina90.h> //定义_nop(),_cli(),_sei()
- //#include <avr/interrupt.h>
- #include <avr/eeprom.h>
- #include "1602.h"
- #include "mb1504.h"
- #define pll_ulock pd2
- #define power_t pd1
- #define power_r pd0
- #define power_ss pd6
- unsigned char step;
- unsigned long step_fre;
- unsigned long fre;
- unsigned long stepcode[7] ={5000,6250,10000,12500,25000,50000,100000};
- void dispfre(void);
- void mode_r(void);
- void mode_t(void);
- unsigned char chk_key(void);
- static void avr_init(void);
- int main(void)
- {
- avr_init();
- for(;;)
- {
- switch (chk_key())
- {
- case 0xe0: //k1 更改步进
- step++;
- if(step>=7)
- {
- step=0;
- }
- step_fre=stepcode[step];
- switch(step)
- {
- case 0:
- lcd_write_string(0,1,pstr(" 5khz"));
- break;
- case 1:
- lcd_write_string(0,1,pstr("6.25khz"));
- break;
- case 2:
- lcd_write_string(0,1,pstr(" 10khz"));
- break;
- case 3:
- lcd_write_string(0,1,pstr("12.5khz"));
- break;
- case 4:
- lcd_write_string(0,1,pstr(" 25khz"));
- break;
- case 5:
- lcd_write_string(0,1,pstr(" 50khz"));
- break;
- case 6:
- lcd_write_string(0,1,pstr(" 100khz"));
- break;
- }
- break;
- case 0xd0: //k2 频率增加
- fre+=step_fre;
- dispfre();
- set_fre(fre,step_fre);
- break;
- case 0xb0: //k3 频率减少
- fre-=step_fre;
- dispfre();
- set_fre(fre,step_fre);
- break;
- case 0x70: //k4 发射
- if(portd&_bv(power_r))
- {
- mode_t();
- lcd_write_string(0,0,pstr("tx"));
- }
- else
- {
- mode_r();
- lcd_write_string(0,0,pstr("rx"));
- }
- break;
- }
- if((pind&_bv(pll_ulock))==0)
- {
- lcd_write_string(10,1,pstr("locked"));
- }
- else
- {
- lcd_write_string(10,1,pstr("unlock"));
- }
- }
- return(0);
- }
- void dispfre(void)
- {
- lcd_write_char(4,0,fre/100000000+0x30);
- lcd_write_char(5,0,(fre%100000000)/10000000+0x30);
- lcd_write_char(6,0,(fre%10000000)/1000000+0x30);
- lcd_write_char(8,0,(fre%1000000)/100000+0x30);
- lcd_write_char(9,0,(fre%100000)/10000+0x30);
- lcd_write_char(10,0,(fre%10000)/1000+0x30);
- lcd_write_char(11,0,(fre%1000)/100+0x30);
- }
- void mode_r(void)
- {
- portd&=~_bv(power_t);
- portd|=_bv(power_r);
- }
- void mode_t(void)
- {
- portd&=~_bv(power_r);
- portd|=_bv(power_t);
- }
- static void avr_init(void)
- {
- ddrb&=0x0f; //b口高4位为输入
- portb|=0xf0; //打开上拉电阻
- ddrd=~_bv(pll_ulock); //设置d口除ul外均为输出脚
- portd|=_bv(power_ss); //开vco电源
- mode_r(); //开接收模式
- pll_init(); //初始化pll端口
- lcd_init(); //初始化lcd
-
- step=2;
- step_fre=stepcode[step];
- fre=435000000;
- set_fre(fre,step_fre);
- lcd_write_string(0,0,pstr("rx= 435.0000 mhz"));
- lcd_write_string(0,1,pstr(" 10khz"));
- return;
- }
- //查键函数
- unsigned char chk_key(void)
- {
- volatile unsigned char temp;
- temp=pinb&0xf0;
- if(temp!=0xf0){
- _delay_ms(20);
- if(temp==(pinb&0xf0)){
- while((pinb&0xf0)!=0xf0);
- _delay_ms(20);
- return(temp);
- }
- }
- return(0);
- }
比较忙,图纸就不整理了,你看程序应该能了解大体的接线。1602的驱动到处都有,也不上了
|