⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 ZARLINK SL2101 C51驱动程序
💻 C
字号:
#include <reg52.h>
#include <intrins.h>
#include <main.h>
#include <i2c.h>
//#include <fq1216.h>
#include <sl2101.h>
#include <lcd.h>

unsigned char togglebit = 0;
unsigned char in_data = 0x26;
unsigned char auto_scan = 0;

unsigned char in_select = 0;
unsigned char i;
unsigned char tune_coarse;
unsigned char tune_fine;
unsigned char total_ch_no=0;
unsigned char cur_ch_no = MAX_CH_NO;
unsigned char tv_format=0;
unsigned int  loop_count=0;
unsigned char pll_count;


void store_ch_freq(void)
{
	if(total_ch_no >= MAX_CH_NO)
		return;
//    lo_freq = (in_freq + UP_IF)*16/100;
    lo_freq = (in_freq + UP_IF)*8/100;
    pdivider_lo = lo_freq&0xff;
    pdivider_hi = ((lo_freq>>8)&0xff);
    i2c_data = pdivider_lo;
	i2c_write(x2402dev,total_ch_no*2);
	delay30ms();
	i2c_data = pdivider_hi;
	i2c_write(x2402dev,(total_ch_no*2)+1);
	total_ch_no++;
}

void restore_ch_freq(void)
{
     i2c_read(x2402dev,cur_ch_no*2);
     pdivider_lo = i2c_data;
	 delay30ms();
     i2c_read(x2402dev,cur_ch_no*2+1);
     pdivider_hi = i2c_data;
	 tcom_data(0x0a);
	 tcom_data(0x0d);
	 dis_data(cur_ch_no);
	 tcom_data(0x20);
	 dis_data(pdivider_hi);//for trace 
	 tcom_data(0x20);
	 dis_data(pdivider_lo);//for trace
	 tcom_data(0x20);
     lo_freq = (unsigned long)(pdivider_hi<<8) + (unsigned long)pdivider_lo;
	 lo_freq = lo_freq*25l;
	 //lo_freq = lo_freq/4l;	 
	 lo_freq = lo_freq/2l;	 
     in_freq = lo_freq - UP_IF;
	 fine_value = 20;                        
     wr_sl2101_up();	
}


void skip_next_ch(void)
{
       if( tune_coarse == 0)
			 in_freq = 5775;
       else if( tune_coarse == 1)
  		     in_freq = 6575;
       else if( tune_coarse == 2)
			 in_freq = 7725;
       else if( tune_coarse == 3)
			 in_freq = 8525;
  	   else if(tune_coarse > 3 && tune_coarse < 48)
	  	     in_freq = (unsigned long) (tune_coarse*800l) +8025l;//11200-3200 = 8000
  	   else if(tune_coarse > 47 && tune_coarse < 61)
			 in_freq = (unsigned long) (tune_coarse*800l) + 7925l; //46300-38400 = 7900
	   else if(tune_coarse > 60  && tune_coarse < 94)
			 in_freq = (unsigned long) (tune_coarse*800l) + 11925l; //60675-48800 = 11900
       else
	   {
	         i2c_data = total_ch_no;
	         i2c_write(x2402dev,120);
             delay30ms();
			 auto_scan = 0;
			 cur_ch_no = 0;
	         restore_ch_freq();
			 
			 init_disfreq();
		     dis_freq();
	   }
	   tune_coarse++;
	   tune_fine = 0;

}

void main()
{   
  unsigned char key;
  unsigned char oldkey;
    
  main_init();
  init_lcd();
  i2c_init();
  
  tcom_data(0x6c); //l
  tcom_data(0x6f); //o
  tcom_data(0x63); //c
  tcom_data(0x6b); //k
  tcom_data(0x65); //e
  tcom_data(0x64); //d
  tcom_data(0x20);

  i2c_read(x2402dev,120);
  if(i2c_data > 50)
	  total_ch_no = MAX_CH_NO;
  else
	  total_ch_no = i2c_data;

  test_lcd();
  init_disfreq();
  wr_sl2101_up();
  wr_sl2101_dn();
  wr_fq1216_if_i();
  dis_freq();

  while(1);

} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -