dzdzz 发表于 2008-8-27 00:14:01

发个锁相环1504程序

#include <avr\io.h>
#include <util\delay.h>
#include <avr\eeprom.h>
#include <avr\pgmspace.h>
#include <avr\interrupt.h>
#include "1504.h"
#include "lcd12864.h"

#defineLE   4
#defineDATA   3
#defineCLK    2

#define CLR_LE   PORTC&=~(1<<LE)
#define SET_LE   PORTC|=(1<<LE)
#define CLR_DATA PORTC&=~(1<<DATA)
#define SET_DATA PORTC|=(1<<DATA)
#define CLR_CLKPORTC&=~(1<<CLK)
#define SET_CLKPORTC|=(1<<CLK)
volatile unsigned char AutoSearchStop=0;
extern volatile unsigned intTimer0InterTimes,Freq[],EEAddr,FreqH[],FreqL;
extern volatile unsigned char Station,Channel,Segment,Select;

void ShortDelay(void)
{
    _delay_us(2);
}

void PLL_Reference(unsigned int R,unsigned char SW)
{
    char i;
    CLR_CLK;
    CLR_LE;
    R<<=1;
    R|=1; //C为1移入16位数据,C为0,移入18位数据
    if(SW)
      R|=0x8000;               
    for(i=0;i<16;i++)
    {
      if(R&0x8000)
            SET_DATA;
      else
            CLR_DATA;
                ShortDelay();
      SET_CLK;
      ShortDelay();
      CLR_CLK;
                ShortDelay();
                R<<=1;
    }
    SET_LE;
    ShortDelay();
    CLR_LE;
        ShortDelay();
}

void PLL_Programe(unsigned char A,unsigned int N)
{
    unsigned char i,temp_A=A;
    unsigned inttemp_N=N;
       
    CLR_CLK;
    CLR_LE;

    temp_A<<=1;
    temp_N<<=5;//11位数据变为16位数据
    for(i=0;i<11;i++)//传送N
    {
      if(temp_N&0x8000)
            SET_DATA;
      else
            CLR_DATA;
                ShortDelay();
      SET_CLK;
                ShortDelay();
      CLR_CLK;
                ShortDelay();
                temp_N<<=1;
    }
    for(i=0;i<8;i++)//传送A
    {
      if(temp_A&0x80)
                        SET_DATA;
      else      
                  CLR_DATA;
      ShortDelay();
      SET_CLK;
                ShortDelay();
      temp_A<<=1;
      CLR_CLK;
                ShortDelay();
    }
        ShortDelay();
    SET_LE;
    ShortDelay();
    CLR_LE;
        ShortDelay();
}

void MSM1504_Init(void)
{
        DDRC|=(1<<LE)|(1<<DATA)|(1<<CLK);
}
void SetFreq(unsigned int F)
{   
    unsigned int N,A;
        if(Segment==1)
          F+=465;
        else
      F+=1070;
    N=F/32;
    A=F%32;
    PLL_Programe(A,N);
}

RedStone 发表于 2008-8-27 09:17:19

顶!我这个程序包里也有MB1504的函数
http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=822285&bbs_page_no=1&search_mode=3&search_text=RedStone&bbs_id=9999

chwei 发表于 2011-8-25 21:17:18

mark

bg6nf 发表于 2012-9-2 20:21:39

很好,谢谢
页: [1]
查看完整版本: 发个锁相环1504程序