基于MSP430的FM收音机,基于TEA5767收音模块制作的收音机(手动搜索电台)
基于MSP430的FM收音机实物.jpg (14.88 KB, 下载次数: 0)
下载附件 保存到相册
基于MSP430的FM收音机实物图
2015-4-8 09:52 上传
基于MSP430的FM收音机实物-3.jpg (22.08 KB, 下载次数: 0)
下载附件 保存到相册
基于MSP430的FM收音机实物图
2015-4-8 09:52 上传
基于MSP430的FM收音机实物-2.jpg (22.58 KB, 下载次数: 0)
下载附件 保存到相册
基于MSP430的FM收音机实物图
2015-4-8 09:52 上传
基于MSP430的FM收音机原理图.jpg (161.36 KB, 下载次数: 0)
下载附件 保存到相册
基于MSP430的FM收音机原理图
2015-4-8 09:54 上传
msp430.h
- /*********基于TEA5767收音模块制作的收音机(手动搜索电台)********/
- #include<msp430.h>
- unsigned char tea5767_write1[]={0x29,0x9e,0x20,0x1a,0x00};//tea5767初始化
- unsigned char tea5767_read[10];
- const unsigned char disp1[]={"FM收音机 手动"};
- const unsigned char disp2[]={"调频: MHZ"};
- #define SCLK_H P2OUT|=BIT0;//tea5767的scl
- #define SCLK_L P2OUT&=~BIT0;
- #define SDA_H P2OUT|=BIT1;//tea5767的data
- #define SDA_L P2OUT&=~BIT1;
- #define rw_h P2OUT|=BIT3;//lcd12864读写端
- #define rw_l P2OUT&=~BIT3;
- #define e_h P2OUT|=BIT4;//lcd12864使能端
- #define e_l P2OUT&=~BIT4;
- unsigned long freq;
- unsigned int pll,key,mode,num;
- unsigned char test;
- void delay1ms(unsigned int i)
- {
- unsigned int j;
- while(i--)
- {
- for(j=0;j<120;j++)
- {}
- }
- }
- void delay()
- {
- unsigned int i;
- for(i=0;i<10;i++)
- {}
- }
- /******************i2c总线设置************************/
- void i2c_start()//i2c开始信号,SCLK高电平期间,SDA电平由高变低
- {
- SDA_H;
- delay();
- SCLK_H;
- delay();
- SDA_L;
- delay();
- SCLK_L;
- delay();
- }
- void i2c_stop()//停止信号,SCL在高电平期间,SDA出现一个上升沿
- {
- SCLK_L;
- delay();
- SDA_L;
- delay();
- SCLK_H;
- delay();
- SDA_H;
- delay();
- }
- void i2c_ack()//应答信号,SCL高电平期间,SDA为低电平
- {
- SDA_L;
- delay();
- SCLK_H;
- delay();
- SCLK_L;
- delay();
- SDA_H;
- delay();
- }
- void i2c_testack()//检测应答,
- {
- SCLK_L;
- delay();
- SCLK_H;
- delay();
- P2SEL&=~BIT1;
- P2DIR&=~BIT1;
- if(P2IN&BIT1)
- {
- test=1;
- }
- else
- {
- test=0;
- }
- delay();
- P2SEL&=~BIT1;
- P2DIR|=BIT1;
- SCLK_L;
- delay();
- }
- void write_byte(unsigned char data)//i2c写一个字节
- {
- unsigned char i;
- for(i=0;i<8;i++)
- {
- if(data&0x80)
- {
- SDA_H;
- }
- else
- {
- SDA_L;
- }
- delay();
- SCLK_H;
- delay();
- SCLK_L;
- delay();
- data=data<<1;
- }
- }
- /***********************TEA5767编程********************/
- void tea5767_wr()//对TEA5767写入数据,连续写入五个字节
- {
- unsigned char i;
- i2c_start();
- write_byte(0xc0);//写地址
- i2c_testack();
- if(!test)
- {
- for(i=0;i<5;i++)
- {
- write_byte(tea5767_write1);
- i2c_ack();
- }
- }
- i2c_stop();
- }
- void get_freq()//由pll值计算频率freq
- {
- unsigned char hlsi;
- unsigned int npll;
- npll=0;
- npll=pll;
- hlsi=tea5767_write1[2]&0x10;//判断写模式下的第三个字节中的
- if(hlsi) //HLSI位是高本振注入还是低本振注入
- {
- freq=(unsigned long)((float)(npll)*(float)8.192-225);//单位KHZ
- }
- else
- {
- freq=(unsigned long)((float)(npll)*(float)8.192+225);//单位KHZ
- }
- }
- void get_pll()//由freq值计算pll
- {
- unsigned char hlsi;
- hlsi=tea5767_write1[2]&0x10;//判断写模式下的第三个字节中的
- if(hlsi) //HLSI位是高本振注入还是低本振注入
- {
- pll=(unsigned long)((float)((freq+225)*4)/(float)32.768);//单位KHZ
- }
- else
- {
- pll=(unsigned long)((float)((freq-225)*4)/(float)32.768);//单位KHZ
- }
- }
- void key_search()//手动搜索电台
- {
- if(key==1)//按键加
- {
- freq=freq+num;
- if(freq>108000)
- {
- freq=87500;
- }
- }
- if(key==2)//按键减
- {
- freq=freq-num;
- if(freq<87500)
- {
- freq=108000;
- }
- }
- get_pll();//由加或减后的freq计算pll
- tea5767_write1[0]=pll/256;
- tea5767_write1[0]&=0x3f;
- tea5767_write1[1]=pll%256;
- tea5767_write1[2]=0xa0;//软件静音
- tea5767_write1[3]=0x1a;
- tea5767_write1[4]=0x00;
- tea5767_wr();//写入TEA5767
- }
- /*************************按键中断*****************/
- #pragma vector=PORT1_VECTOR //P1口按键中断
- __interrupt void port1(void)
- {
- if(P1IFG&0X04)//P1.2选择手动搜索模式还是自动搜索
- {
- mode^=1;
- }
- if(P1IFG&0X01)//P1.0按键加
- {
- key=1;
- if(mode==1)
- {
- num=1000;
- key_search();
- }
- else
- {
- num=100; //微调
- key_search();
- }
- }
- if(P1IFG&0X02)//P1.1按键减
- {
- key=2;
- if(mode==1)
- {
- num=1000;
- key_search();
- }
- else
- {
- num=100;//微调
- key_search();
- }
- }
- P1IFG=0X00;
- delay1ms(10);//延时消抖
- }
- /*******************LCD12864显示*********************/
- void sendbyte(unsigned int data)//向LCD发送一个字节
- {
- unsigned char i;
- for(i=0;i<8;i++)
- {
- if(data&0x80)
- {
- rw_h;
- }
- else
- {
- rw_l;
- }
- e_l;
- e_h;
- data=data<<1;
- }
- }
- void write_com(unsigned int comm)//写指令
- {
- sendbyte(0xf8);
- sendbyte(comm&0xf0);
- sendbyte((comm<<4)&0xf0);
- //delay1ms(1);
- }
- void write_data(unsigned char data0)//写数据
- {
- sendbyte(0xfa);
- sendbyte(data0&0xf0);
- sendbyte((data0<<4)&0xf0);
- //delay1ms(1);
- }
- void lcd_init()//LCD初始化
- {
- write_com(0x30);
- write_com(0x0c);
- write_com(0x01);
- write_com(0x06);
- }
- void display()//液晶显示(不变的内容)
- {
- unsigned char i;
- i=0;
- write_com(0x80);
- while(disp1!='\0')
- {
- write_data(disp1[i++]);
- }
- i=0;
- write_com(0x90);
- while(disp2!='\0')
- {
- write_data(disp2[i++]);
- }
- }
- void display0()//液晶显示(变化的内容)
- {
- write_com(0x93);//调频显示频率
- write_data((freq)/100000+'0');
- write_data((freq)/10000%10+'0');
- write_data((freq)/1000%10+'0');
- write_data('.');
- write_data(freq/100%10+'0');
- }
- void port_init()//引脚初始化
- {
- P2SEL&=0X00;
- P2DIR|=0XFF;
- P2OUT|=0xFF;
- P1SEL&=0X00;
- P1DIR&=0X00;
- P1IE|=0Xff;
- P1IES|=0Xff;
- P1IFG&=0X00;
- P1OUT|=0XFF;
- }
- void main()
- {
- WDTCTL=WDTPW+WDTHOLD;
- mode=0;
- key=1;
- pll=0x299e;
- freq=87500;
- port_init();
- _EINT();
- lcd_init();
- display();
- tea5767_wr();
- display();
- while(1)
- {
- display0();
- }
- }
复制代码
|