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

📄 init.c

📁 银杏科技有限公司dsp实验开发板的实验程序
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <string.h>
#include <stdio.h>
/*
 *  ======== main ========
 */

int s;
char *b;

#define  UART_COUNTER  0x62
#define  KEYIN_COUNTER 0X61
#define  LCD_SIZE      23
#define  KEY_SIZE      6
#define  LED_SIZE      14

ioport unsigned port8000;     /*  for CTRL word */
ioport unsigned porte000;     /*  for DC MOTOR run */
ioport unsigned portc000;     /*  for LEDs show */
ioport unsigned portf000;     /*  for STEPMOTOR */

unsigned int  CtrlWord=0;
char LCD_Buffer[LCD_SIZE]=
      {0x55,0x66} ;          /* LCD SHOW's buffer */
char KEY_Buffer[KEY_SIZE];   /* KEY INPUT's buffer */
int  Iskey=0; 			     /* if Iskey!=0,then have KEY in */
                             /* its high 8 bits are key code ! */
char LED_Buffer[LED_SIZE]=
      {0x55,0x77};           /* LED SHOW's buffer */                             
int  NowLine=1,NowCol=0;
int  IsQuitKey=0;            /*  if == 1, quit key input */				

unsigned int  chk_prog28000(void);
unsigned int  chk_data8000(void);
void u_printf(char *buf,int size);
void key_input(char *buf,int size);
void pllx100();
void pllx10();
void speak(int length,int flag);

int test()
{
   int i;
   
   i=0;
   
   return(i);
}
   
void mydelay()
{    /*  when clkout=10MHz, about 0.2s  */
   int i,j;

   for(i=0;i<500;i++)
     for(j=0;j<1000;j++);

}

void mydelay1()
{    /*  when clkout=10MHz, about 0.2s  */
   int j,i;

   for(i=0;i<200;i++)  
     for(j=0;j<1000;j++);

}


void error_sound(int error)
{

    if(error==1)
    {  speak(2000,1);mydelay();  } 
    else
    {  speak(7500,1);mydelay();
       speak(7500,1);mydelay();  }

}

int is_getkey(void)
{  int i;

    if(( KEY_Buffer[0] == 'E') && (KEY_Buffer[5] == 0x0d))    
    {   Iskey=((KEY_Buffer[4] & 0xff) << 8 );
        Iskey |= (KEY_Buffer[3] & 0xff);
        for(i=0;i<6;i++)
           KEY_Buffer[i]=0;     /*  clear key buffer */
    }    
    else
       Iskey=0;
    return(Iskey);      /*  return key code, low 8 bit is code  */                                                 


}
int get_key(int iswait)
{ volatile int *addr_counter;
  int i;
    
    Iskey=0;
    key_input(&KEY_Buffer[0],6);
    if(iswait == 0)     /*  if iswait==1, then must wait for rev end,
                            else return direct !   */
       return(Iskey);      /*  return key code  */                                                 
  
    addr_counter = (int *)KEYIN_COUNTER;  
    while( *addr_counter);  /*  wait for a key input... */
    
    if(( KEY_Buffer[0] == 'E') && (KEY_Buffer[5] == 0x0d))    
    {   Iskey=((KEY_Buffer[4] & 0xff) << 8 );
        Iskey |= (KEY_Buffer[3] & 0xff);
        for(i=0;i<6;i++)
           KEY_Buffer[i]=0;     /*  clear key buffer */
    }    
    else
    {
        for(i=0;i<6;i++)
           KEY_Buffer[i]=0;     /*  clear key buffer */
        mydelay();
    }    
    return(Iskey);      /*  return key code, low 8 bit is code  */                                                 

}



int lcd_printf(int ln, int col, char *buf, int iswait)
{   volatile int *addr_counter;
    
    addr_counter = (int *)UART_COUNTER;
    
    LCD_Buffer[2]=ln;     /*  which LN will show the string */
    LCD_Buffer[3]=col;    /*  which COL will show string */
    LCD_Buffer[4]=strlen(buf)/2;  /* how many chinese char(2 byte) will show */
    
    memcpy(&LCD_Buffer[5],buf, LCD_Buffer[4]*2);
    
    LCD_Buffer[21]=0x88;
    LCD_Buffer[22]=0x99;
    
    u_printf(&LCD_Buffer[0],23);
    
    if(iswait == 1)     /*  if iswait==1, then must wait for send end,
                            else return direct !   */

      while( *addr_counter);
    
    return( *addr_counter);  /*  return number of left char will not send  */                                                 
}

int led_printf(char *buf, int iswait)
{   volatile int *addr_counter;
    int j;
    
    addr_counter = (int *)UART_COUNTER;
    
                         /* if buf="", clr LED */
    for(j=0;j<8;j++)
    {  if(*buf == '\0')
            LED_Buffer[11-j]=0xf;
        else
        {  if( *buf == ' ')
           {  LED_Buffer[11-j]=0xf; buf++; }
           else
           {  if( *buf <= '9') 
                  LED_Buffer[11-j]= *buf++ & 0xf;
              else
                  LED_Buffer[11-j]= *buf++-'a'+0xa;    
           }
         }         
    }        
           
    LED_Buffer[12]=0x88;
    LED_Buffer[13]=0x99;
    
    u_printf(&LED_Buffer[0],14);
    
    if(iswait == 1)     /*  if iswait==1, then must wait for send end,
                            else return direct !   */

      while( *addr_counter);
    
    return( *addr_counter);  /*  return number of left char will not send  */                                                 
}

void key_shown(char key)
{  char buf[3];
   int  noshow=0;
   
   switch(key)
   {  
       case 59:   /*  ESC */
           IsQuitKey=1;
           return;
       case 60:   /*  '4'  */
           strcpy(buf,"4");
           break; 
       case 61:        
           strcpy(buf,"8");
           break; 
       case 62:        
           strcpy(buf,"C");
           break; 
       case 51:   /*  '1' */
           strcpy(buf,"1");
           break;
       case 52:   /*  '5'  */
           strcpy(buf,"5");
           break; 
       case 53:   /* '9' */     
           strcpy(buf,"9");
           break; 
       case 54:        
           strcpy(buf,"D");
           break;
       case 43:   /*  '2' */
           strcpy(buf,"2");
           break;
       case 44:   /*  '6'  */
           strcpy(buf,"6");
           break; 
       case 45:   /* 'a' */     
           strcpy(buf,"A");
           break; 
       case 46:        
           strcpy(buf,"E");
           break;                 
       case 35:   /*  '3' */
           strcpy(buf,"3");
           break;
       case 36:   /*  '7'  */
           strcpy(buf,"7");
           break; 
       case 37:   /* 'b' */     
           strcpy(buf,"B");
           break; 
       case 38:        
           strcpy(buf,"F");
           break;                 
       case 29:   /*  '+' */
           strcpy(buf,"+");
           break;
       case 21:   /*  '-'  */
           strcpy(buf,"-");
           break; 
       case 13:   /* 'x' */     
           strcpy(buf,"X");
           break; 
       case 5:        
           strcpy(buf,"/");
           break;                 
       case 30:   /*  '0' */
           strcpy(buf,"0");
           break;
       case 22:   /*  '.'  */
           strcpy(buf,".");
           break; 
       case 14:   /* ';' */     
           strcpy(buf,":");
           break; 
       case 6:    /*  RUN key  */    
           noshow=1;
           break; 
       default:
           noshow=1;
           break;                    
                            
    }       
    
    if( noshow == 1)
       return;
                       
    lcd_printf(NowLine,NowCol,buf,0);
    //mydelay1();    /* wait MCU to shown */
    NowCol++;
    if((NowCol%8) == 0)
    {  NowCol=0; NowLine++;  } 
}      
 
void lcd_clr(int iswait)
{   volatile int *addr_counter;
    
    addr_counter = (int *)UART_COUNTER;
    
    LCD_Buffer[2]=0xff;  
    LCD_Buffer[3]=0xff;    
    LCD_Buffer[4]=0xff;  
    
    LCD_Buffer[21]=0x88;
    LCD_Buffer[22]=0x99;
    
    u_printf(&LCD_Buffer[0],23);
    
    if(iswait == 1)     /*  if iswait==1, then must wait for send end,
                            else return direct !   */
      while( *addr_counter);
    
}

int test_mem(int allmem)
{  int memok,test_ret;

⌨️ 快捷键说明

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