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

📄 test8.c

📁 5402开发板附带的源程序
💻 C
字号:
#include "REG5402.h"

int timer1_over;
int read;

void serialbyte_send(unsigned int byte,int abc)
{
   unsigned int i,k,a;

   if(abc==1) 
    {
      a=byte>>8;

      TXD=TXD_bitclear;              /* send start bit */
      PRD1=0x1df;
      TCR1=0x02eb;
      for(;timer1_over==0;);
      timer1_over=0;
    
      for(i=0;i<8;i++)              /* send 8 bits data */
      {
         k=a&0x0001;
         TXD=(k!=0)?TXD_bitset:TXD_bitclear;
         PRD1=0x1df;
         TCR1=0x02eb;
         for(;timer1_over==0;);
         timer1_over=0;
  
         a=a>>1;
      }

      TXD=TXD_bitset;                 /* send end bit */
      PRD1=0x1df;   
      TCR1=0x02eb;
      for(;timer1_over==0;);
      timer1_over=0;
   }

   a=byte&0x00ff;

   TXD=TXD_bitclear;
   PRD1=0x1df;
   TCR1=0x02eb;
   for(;timer1_over==0;);
   timer1_over=0;

   for(i=0;i<8;i++)
   {
      k=a&0x0001;
      TXD=(k!=0)?TXD_bitset:TXD_bitclear;
      PRD1=0x1df;
      TCR1=0x02eb;
      for(;timer1_over==0;);
      timer1_over=0;

      a=a>>1;
   }

   TXD=TXD_bitset;
   PRD1=0x1df;   
   TCR1=0x02eb;
   for(;timer1_over==0;);
   timer1_over=0; 
}

void cpu_init()
{
   
   PMST=0x3fa0;      
   SWWSR=0x7fff;
   SWCR=0x0000;
   BSCR=0x0002;
   IMR=0; IFR=IFR;

   SPSA1=0xe;        
   SPSD1=0x3020;     
}

void timer1_init()       /* Sample time */
{
   PRD1=0x1df;      
   TCR1=0x02eb;     
                     
   IMR=IMR|0x0080;
}

main()
{
   read=0;
   asm(" ssbx intm"); 
   cpu_init();
   timer1_init();
   asm(" rsbx intm");

   for(;;)
   {
      serialbyte_send(0xffff,1);
      read=(READS&0x0fff);   
      serialbyte_send(read,1);    
   }
}

interrupt void timer1_int()
{
   timer1_over=1;
   TCR1=0x02db;
}

⌨️ 快捷键说明

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