当前位置: 代码迷 >> 单片机 >> AS44CC373调制器的程序解决办法
  详细解决方案

AS44CC373调制器的程序解决办法

热度:122   发布时间:2016-04-28 16:31:58.0
AS44CC373调制器的程序
求MC44CC373 或AS44CC373这方面的C51单片机编程资料或源码,不胜感激!

------解决方案--------------------
#include "reg52.h"
#define FALSE 0
#define TRUE 1
//#define SET 1
//#define CLR 0
#define C1_H 0x90
#define C0_L 0x08
sbit SDA=P3^0;
sbit SCL=P3^1;


void delay(unsigned char m)
{ char i;
for(i=m;i>=0;i--)
;
}
void start_i2c(void)
{
SDA=1;
SCL=1;
delay(2);
SDA=0;
delay(2);
SCL=0;
 
}

void stop_i2c(void)
{
SCL=0;
SDA=0;
delay(2);
SCL=1;
delay(2);
SDA=1;
//delay(2);
//SCL=0;
 
}
void send_1(void)
{
SCL=0;
SDA=1;
delay(2);
SCL=1;
delay(2);
}

void send_0(void)
{
SCL=0;
SDA=0;
delay(2);
SCL=1;
delay(2);
}

bit check_ack(void)
{
bit q;
SCL=0;
SDA=1;
delay(1);
q=SDA;
delay(1);
SCL=1;
delay(2);
if(q==1)
return FALSE;
else
return TRUE;
}

void write_i2c_byte(unsigned char temp)
{
unsigned char i;
for(i=0;i<8;i++)
{
if((temp<<i)&0x80)
send_1();
else
send_0();
}
SCL=0;
}

bit signal_send(unsigned int tmp)
{
unsigned char fm_h,fm_l;
bit ack=1;
fm_h=(unsigned char)(tmp>>6);
fm_l=(unsigned char)(tmp<<2)&0xff;
  
start_i2c();
write_i2c_byte(0xce);
ack=check_ack();
if(ack==0)
return 0;
write_i2c_byte(fm_h);
ack=check_ack();
if(ack==0)
return 0;
write_i2c_byte(fm_l);
ack=check_ack();
if(ack==0)
return 0;
write_i2c_byte(C1_H);
ack=check_ack();
write_i2c_byte(C0_L);
ack=check_ack();
if(ack==0)
return 0; 
stop_i2c();
return 1;
}
void main(void)
{
unsigned char acknow=1;
//unsigned int temp=0x0b9;
 while(1)
 {
//key_fun();
while(!acknow)
{
acknow=signal_send(freq_data);
}
}
  相关解决方案