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

📄 f33xdr30190d_10_01.c

📁 驅動DR30190 IC 使用10 bit Mode
💻 C
字号:
//
// File Name:F33xDR30139D_10_01.c
//----------------------------------------------------------------------------
// Project Name: DR30139D
// Module Name:  DR30190D 10-bit PWM Mode Operation
//----------------------------------------------------------------------------
//
// Company:Semiconductor Device Solution, Inc 
//         http://www.sdsi.com.tw/
//
// Engineer: Owen Chen
// Create Date: 09:30:00 05/20/2007 
// Revision: 1.01
//
// Description:
//              10 bit Mode
//                                           
// 
// Target Devcies: C8051F330
//
// Tool Chain: Tool chain: KEIL Eval 'c'
// Copyright Semiconductor Device Solution, Inc .All Rights Reserved
//
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------

#include <c8051f330.h>              // SFR declarations
#define ShowLength  8               // How many show            
#define ShowByte    3               // How many byte 
#define IV          10              // 10 bits PWM Mode  
#define N           2               // Latch Number
#define BRN         16         
#define High        1
#define Low         0 

//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------

void Port_IO_Init();
void Reset_Sources_Init();
void WriteByte(unsigned short ShowData);
void WriteLMData2DR3019(unsigned char Index);
void WriteBRData2DR3019(unsigned char Index);	
void DelayTime_1us(int num);

//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------

sbit DR30139_SDI = P1^0;        // DR30139D Serial data input
sbit DR30139_SCK = P1^1;        // DR30139D Synchronous clock
sbit DR30139_LBI = P1^2;        // DR30139D At the falling edge 
sbit LED         = P1^3;  


//-----------------------------------------------------------------------------
// Global VARIABLES
//-----------------------------------------------------------------------------

unsigned short LM[ShowLength][ShowByte]={
                                              {0x03FF,0x0000,0x0000},
											  {0x0000,0x03FF,0x0000},
											  {0x0000,0x0000,0x03FF},
											  {0x03FF,0x03FF,0x0000},
											  {0x0000,0x03FF,0x03FF},
											  {0x03FF,0x0000,0x03FF},
											  {0x03FF,0x03FF,0x03FF},
											  {0x0000,0x0000,0x0000},					  
                                           };

unsigned short BR[ShowLength][ShowByte]={
                                              {0x03F0,0x03F0,0x03F0},
											  {0x03F0,0x03F0,0x03F0},
											  {0x03F0,0x03F0,0x03F0},
											  {0x03F0,0x03F0,0x03F0},
											  {0x03F0,0x03F0,0x03F0},
											  {0x03F0,0x03F0,0x03F0},
											  {0x03F0,0x03F0,0x03F0},
											  {0x0000,0x0000,0x0000},					  
                                           };
unsigned short temp;

//=============================================================================
// MAIN Routine
//=============================================================================
//start main

void main()
{   
     
	 
//-----------------------------------------------------------------------------
// MCU Power On Initail
//-----------------------------------------------------------------------------

     PCA0MD   &= ~0x40;    // disable WDT temporarily 
     OSCICN    = 0x83;;    // SYSCLK = 6.25MHz 
     
     Port_IO_Init();

	 DelayTime_1us(1000);	   

	 DR30139_LBI = Low; 
	 
	 
	 WriteBRData2DR3019(1);

     Reset_Sources_Init();
     
	 while(1)
	 {
       
	   WriteBRData2DR3019(1);
	   
	   LED =1;

	   WriteLMData2DR3019(1);
	   DelayTime_1us(0xFFFF);
	   
	   WriteLMData2DR3019(2);
	   DelayTime_1us(0xFFFF);

	   WriteLMData2DR3019(3);
	   DelayTime_1us(0xFFFF);

	   WriteLMData2DR3019(4);
	   DelayTime_1us(0xFFFF);

      
	   WriteLMData2DR3019(5);
	   DelayTime_1us(0xFFFF);

	   WriteLMData2DR3019(6);
	   DelayTime_1us(0xFFFF);

	   WriteLMData2DR3019(7);
	   DelayTime_1us(0xFFFF);

	   WriteLMData2DR3019(8);
	   DelayTime_1us(0xFFFF);     
       
	 
      }
 
	 
}


//=============================================================================
// Initialization Subroutines
//=============================================================================
//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
void Port_IO_Init()
{
    // P1.0  -  DR30190_SDI,  Push-Pull,  Digital
    // P1.1  -  DR30190_SCK,  Push-Pull,  Digital
    // P1.2  -  DR30190_LBI ,  Push-Pull,  Digital
    // P1.3  -  LED,  Push-Pull,  Digital

    P0MDOUT   = 0xFF;
	P1MDOUT   = 0xFF;
    XBR1      = 0x40;
}

//-----------------------------------------------------------------------------
// Reset_Sources_Init
//-----------------------------------------------------------------------------
// Description:
//             Power Fail reset
//-----------------------------------------------------------------------------

void Reset_Sources_Init()
{
    int i = 0;
    VDM0CN    = 0x80;
    for (i = 0; i < 350; i++);  // Wait 100us for initialization
    RSTSRC    = 0x02;
}

//=============================================================================
// Function Service
//=============================================================================
//-----------------------------------------------------------------------------
// Write LM Data to DM3019
//-----------------------------------------------------------------------------
void WriteLMData2DR3019(unsigned char Index)
{
     unsigned char i,j;
     unsigned short temp;

	
	 
	 
	 for(i=0;i<N;i++)
	 {
	    
		 
		 for(j=0;j<ShowByte;j++)   // Sent 3 Byte
	     {
            temp = LM[Index-1][j];
		    WriteByte(temp);
	     }
    
         
	 }

	  DelayTime_1us(2);
	  DR30139_LBI = High;
      DelayTime_1us(2);
	  DR30139_LBI = Low;


}



//-----------------------------------------------------------------------------
// Write Data
//-----------------------------------------------------------------------------
void WriteBRData2DR3019(unsigned char Index)
{
     unsigned char i,j;
     unsigned short temp;

     
	 
	 for(i=0;i<BRN;i++)
	 {
	    
		 for(j=0;j<ShowByte;j++)   // Sent 3 Byte
	     {
            temp = BR[Index-1][j];
		    WriteByte(temp);
	     }
    
         
	 }

	  DelayTime_1us(2);
	  DR30139_LBI = High;
	  DelayTime_1us(1);
	  DR30139_SCK = High;
	  DelayTime_1us(1);
	  DR30139_SCK = Low;
      DelayTime_1us(2);
	  DR30139_LBI = Low;


}

//-----------------------------------------------------------------------------
// Write Data
//-----------------------------------------------------------------------------

void WriteByte(unsigned short ShowData)
{
    unsigned char i;

	
    ShowData<<=6;
	
	for(i=0;i<IV;i++)        // Sent 10 bits
	{
       if(ShowData&0x8000)
			DR30139_SDI= High;
		else
			DR30139_SDI = Low;

		DR30139_SCK = High;
		 ShowData<<=1;
		DR30139_SCK = Low;
	}

}

//=============================================================================
// Interrupt Service Routines
//=============================================================================
//-----------------------------------------------------------------------------
// Dealy Time for 1 us
//-----------------------------------------------------------------------------
//
//This routine changes the state of the LED whenever Timer2 overflows.
//
//-----------------------------------------------------------------------------
void DelayTime_1us(int num)
{
	unsigned int i,j;
	for(i=1;i<num;i++)	
		for(j=0;j<=30;j++)
			;
}

//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------

⌨️ 快捷键说明

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