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

📄 驱动程序 读数据.c

📁 本程序为AT89C51单片机下语音芯片ISD2560的驱动程序
💻 C
字号:
#include<reg51.h>
#define uchar unsigned char

float data nongdu;
uchar data bai,shi,gewei,one,two,xshu,zhshu,count;
uchar data num[6];
uchar code add[]={0,20,40,60,80,100,120,140,160,180,200,220,250};
sbit A8=P2^7;
sbit A9=P2^6;
sbit isd_ce=P2^4;
sbit PD=P2^0;
sbit EOM=P3^2;
bit flag;

/********得到各个位的值********/
void get_wei()
{
   int nongdu2;
   zhshu=nongdu;
   nongdu=nongdu*100;
   nongdu2=nongdu;
   xshu=nongdu2%100;
   bai=nongdu2/10000;
   nongdu2%=10000;
   shi=nongdu2/1000;
   nongdu2%=1000;
   gewei=nongdu2/100;
   nongdu2%=100;
   one=nongdu2/10;
   two=nongdu2%10;
}

/*********小数的读法**********/
void getxshu()
{
   num[count]=11;
   count++;
   if(two)
   {
      num[count]=one;
      count++;
      num[count]=two;
      count++;   
   }
   else{num[count]=one;count++;}
}

/*********整数部分的读法**********/
uchar num_to_read()
{
   count=0;
   if(nongdu==0)
   {
      num[count]=0;
      count++;
      return(0);
   }
   else
   {
      if(xshu==0)
      {
         flag=0;
      }
      else flag=1;
      if(zhshu==0)
      {
         num[count]==0;
         count++;
         getxshu();       //xshu must not be 0
         return(0);
      }
      if(bai)return(0);         
      else if(!shi)            //shi==0 qie zhshu must not be 0
           {                 
              num[count]=gewei;
              count++;
              if(flag)getxshu();
              return(0);
            }
            else if(shi==1)      
                 {  
                    num[count]=10;
                    count++;       
                    if((!gewei)&&flag)     //shi==1&&ge==0
                    {                        
                        getxshu();
                        return(0);
                    }
                    if(gewei)
                    {                   //shi==1&&ge!=0
                        num[count]=gewei;
                        count++;
                        if(flag)getxshu();
                        return(0);
                    } 
                 }
                 else                  //shi!=1,shi!=0  
                 {
                    num[count]=shi;
                    count++;
                    num[count]=10;
                    count++;
                    if(!gewei)           //shi!=1&shi!=0&ge=0  
                    {
                       if(flag)getxshu();     
                       return(0);
                    }
                    else
                    {
                       num[count]=gewei;
                       count++;
                       if(flag)getxshu();
                       return(0);
                     }
                 }     
   }
}

/***********得到相应的地址**********/
void covert()
{
   uchar count1;
   count1=count;
   for(;count1>=0;count1--)
   {
      num[count1]=add[num[count1]];
      if(!count1)break;
   }      
}

void delay()
{
   unsigned int cout;
   cout=40000;
   for(;cout>0;cout--);
}

/************中断响应**********/
void eom() interrupt 0 using 2
{
   EX0=0;
   isd_ce=1;
   //PD=1;
   delay();
   EX0=1;
}

/***********读出相应的数**********/
/*void read()
{
   uchar i;
   for(i=0;i<count;i++)
   {
      P1=num[i];
      A8=A9=0;
      PD=0;
      isd_ce=0;
      while(1)
      {
        if(EOM==0)
        {
         if(EOM==0)
         {
          isd_ce=1;
          PD=1;
         }
       }
      } 
   }   
}*/
void read()
{
   unsigned char i;
    //delay();
    EA=1;
    IT0=1;
    EX0=0;
    A8=A9=0;
    isd_ce=1;
    PD=0;
    EX0=1;
  while(1){
    P1=0xfa;
    isd_ce=0;
    while(isd_ce==0);
    delay();
    isd_ce=1;	
    for(i=0;i<count;i++)                            
    {    
      P1=num[i];
      //P1=0X00; 
      isd_ce=0;
      while(isd_ce==0);  
      //delay();       
    } 
    }
}    

void main()
{
   isd_ce=1;
   PD=1;
   nongdu=12.51;
   get_wei();
   num_to_read();
   covert();
   read();
}   
   
   
      
  

⌨️ 快捷键说明

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