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

📄 target.#3

📁 基于MST-G240128点阵液晶的 状态机机制 人机界面四级滚屏菜单 源代码 ,带时间片机制模拟操作系统
💻 #3
📖 第 1 页 / 共 2 页
字号:
   P0MDOUT = 0x51;    // P0.0(UART0_TX)、P0.4(UART1_TX)和P0.6(CEX0)设置为推挽输出方式. 
                      // P0.7 = 1.P0.6 = 1.
   P1MDIN  = 0xFF;    // P1口设置为数字I/O.
   P1MDOUT = 0xFC;    // P1[7..2]设置为推挽输出,P1[1..0]为数字输入.
   P1      = 0xFF;    // 

   P2MDIN  = 0xFF;    // P2口设置为数字I/O.
   P2MDOUT = 0xC0;    // P2[7..6]设置为推挽输出,P2[5..0]为数字输入.
   P2      = 0xFF;    // UF_SEL[1..0]  = "11";

   P3MDIN  = 0xFF;    // P3口设置为数字I/O.
   P3MDOUT = 0x00;    // P3[7..0]设置为数字输入.
   P3      = 0xFF;    // ;  

   SFRPAGE = 0x0f;    // P5 SFR PAGE.

   P4MDOUT = 0xFF;    // P4口设置为推挽输出方式.
   ucP4DATA= 0xC0;    // 111_00000. Page 0.
   P4 = ucP4DATA;     // nWR ='1';nRD ='1';ALE ='0'; 

   P5MDOUT = 0xFF;    // P5口设置为推挽方式,可控硅触发脉冲信号.       
   ucP5DATA= 0x7F;    // PulseOUT_LED = 0, PulseOUT[6..0] = 0xFF, All OFF; 
   P5 = ucP5DATA;               
 
   P6MDOUT = 0xFF;    // P6口,         高8位地址,设置为推挽方式.  
   P7MDOUT = 0xFF;    // P7口,EMIF数据/低8位地址,设置为推挽方式. 

   SFRPAGE = 0x00;
   EMI0CF  = 0x00;    // 0010_0101: Port On P4~P7;multiplexed mode;Internal Only;     
// Bits3-2: EMD1-0: EMIF Operating Mode Select.
//          00:     Internal Only.
//          01:     Split Mode without Bank Select.
//          10:     Split Mode with Bank Select.
//          11:     External Only.
   EMI0TC = 0x00;     // 00 0010 01. 
// Bits7-6: EAS1-0:      EMIF Address Setup Time Bits.
//          00/01/10/11: Address setup time = 0/1/2/3 SYSCLK cycles.

// Bits5-2: EWR3-0:             EMIF /WR and /RD Pulse-Width Control Bits.
//          0000/0001/...1111/: 1/2/...15 SYSCLK cycles.

// Bits1-0: EAH1-0:      EMIF Address Hold Time Bits.
//          00/01/10/11: Address hold time = 0/1/2/3 SYSCLK cycles.
// T6963的读写脉冲宽度要求大于80nS;  

   
    // P0.0  -  TX0 (UART0), Push-Pull,  Digital
    // P0.1  -  RX0 (UART0), Open-Drain, Digital
    // P0.2  -  SDA (SMBus), Open-Drain, Digital
    // P0.3  -  SCL (SMBus), Open-Drain, Digital
    // P0.4  -  TX1 (UART1), Push-Pull,  Digital
    // P0.5  -  RX1 (UART1), Open-Drain, Digital
    // P0.6  -  CEX0 (PCA),  Open-Drain, Digital
    // P0.7  -  INT0 (Tmr0), Open-Drain, Digital

    // P1.0  -  INT1 (Tmr1), Open-Drain, Digital
    // P1.1  -  Unassigned,  Open-Drain, Digital
    // P1.2  -  Unassigned,  Open-Drain, Digital
    // P1.3  -  Unassigned,  Open-Drain, Digital
    // P1.4  -  Unassigned,  Open-Drain, Digital
    // P1.5  -  Unassigned,  Open-Drain, Digital
    // P1.6  -  Unassigned,  Open-Drain, Digital
    // P1.7  -  Unassigned,  Open-Drain, Digital
}


/***********************************************************************
* 名称:Interrupt_Init()
* 功能:中断控制器初始化.
* 入口参数:无     
* 出口参数:无
* 说明:    
***********************************************************************/
void Interrupt_Init(void)
{
   // ET0 = 1;					// Enable Timer0 interrupt(125uS timer)(Priority: 1)
   // ES0 = 1;					// Enable UART0 interrupt(Priority: 4).
   // EIE2 = EIE2|0x40;		// ES1=1: Enalbe UART1 interrupt(Priority: 20)
   // EIP2 = EIP2|0x40;	   // PS1=1: Set priority of the UART1 interrupt.
   // ET1 = 1;				   // Enable Timer1 interrupt(UART1 BautRate)
   ET2 = 1;				   // Enable Timer2 interrupt
	PT2 = 1;             // Set T2 to High priority.
   // EIE2 = EIE2|0x01;		// Enalbe Timer3 interrupt
   // EIE2 = EIE2|0x02;		// Enalbe ADC0   interrupt
   // EIE2 = EIE2|0x04;		// Enalbe Timer4 interrupt
}

/***********************************************************************
* 名称:RstSTATUS()
* 功能:读取单片机复位记录
* 入口参数:无     
* 出口参数:无
* 说明:    
***********************************************************************/
uint8 RstSTATUS(void)
{
   uint8 ucTMP;
   return ucTMP;
}

/***********************************************************************
* 名称:WDT_Setting()
* 功能:看门狗设置
* 入口参数:WdtIvl,看门狗溢出时间设置.     
* 出口参数:无
* 说明:    
***********************************************************************/
void WDT_Setting(unsigned char WdtIvl)
{
   unsigned char ucTMP;
   ucTMP = WdtIvl & 0x07;
   WDTCN = ucTMP; // Set the Watchdog Timeout Interval, for 24MHz SYSCLK,~651uS.
// WDTCN(xxxxx111): Watchdog Timer Control Register.   
// Bits7-0: WDT Control.
// Writing 0xA5 both enables and reloads the WDT.
// Writing 0xDE followed within 4 system clocks by 0xAD disables the WDT.
// Writing 0xFF locks out the disable feature.
// Bit4: Watchdog Status Bit (when Read, 1: WDT is active).
// Bits2-0: Watchdog Timeout Interval Bits.
}

/***********************************************************************
* 名称:WDT_Disabled()
* 功能:看门狗禁止
* 入口参数:无     
* 出口参数:无
* 说明:    
***********************************************************************/
void WDT_Disabled(void)
{
// WDTCN(xxxxx111): Watchdog Timer Control Register.   
// Bits7-0: WDT Control.
// Writing 0xA5 both enables and reloads the WDT.
// Writing 0xDE followed within 4 system clocks by 0xAD disables the WDT.
// Writing 0xFF locks out the disable feature.
// Bit4: Watchdog Status Bit (when Read, 1: WDT is active).
// Bits2-0: Watchdog Timeout Interval Bits.
   WDTCN = 0xDE;         // Disable WDT.
   WDTCN = 0xAD;
}

/***********************************************************************
* 名称:WDT_Disabled()
* 功能:看门狗重装载
* 入口参数:无     
* 出口参数:无
* 说明:    
***********************************************************************/
void WDT_Reload(void)
{
   WDTCN = 0xA5;        // Enable WDT or Reload the WDT.
}


/***********************************************************************
* 名称:PCA_Init()
* 功能:PCA初始化.
* 入口参数:无     
* 出口参数:无
* 说明:CEX0产生7.8125KHz占空比为50%的方波.    
***********************************************************************/
void PCA_Init(void)
{
   SFRPAGE = 0x00;
   PCA0MD = 0x00;  // 0 000 000 0 
   // System clock divided by 12.
   // Bit7: CIDL: PCA0 Counter/Timer Idle Control.
   //       0/1:  PCA0 continues / STOP when CPU is in Idle Mode.
   // Bits6-4: UNUSED. Read = 000b, Write = don't care.
   // Bits3-1: CPS2-CPS0: PCA0 Counter/Timer Pulse Select.
   //          000:       System clock divided by 12.
   // Bit0: ECF: PCA Counter/Timer Overflow Interrupt Enable.
   //       0/1: Disable/Enable the CF interrupt.
   PCA0CN = 0x40;
   // PCA0 Counter/Timer enabled.      
   // Bit7: CF:  PCA Counter/Timer Overflow Flag.
   // Bit6: CR:  PCA0 Counter/Timer Run Control.
   //       0/1: PCA0 Counter/Timer disabled / enabled.
   // Bit5: CCF5: PCA0 Module 5 Capture/Compare Flag.
   // Bit4: CCF4: PCA0 Module 4 Capture/Compare Flag.
   // Bit3: CCF3: PCA0 Module 3 Capture/Compare Flag.
   // Bit2: CCF2: PCA0 Module 2 Capture/Compare Flag.
   // Bit1: CCF1: PCA0 Module 1 Capture/Compare Flag.
   // Bit0: CCF0: PCA0 Module 0 Capture/Compare Flag.
   PCA0L = 0x00;       // PCA Counter/Timer Low Byte
   PCA0H = 0x00;       // PCA Counter/Timer High Byte	
	

   //Module 0:Generate 7.8125kHz Square Wave.
   PCA0CPM0 = 0x42;    // Enable PCA Module 0.PWM Mode.
   // Bit7: PWM16n: 16-bit Pulse Width Modulation Enable
   //          0/1: 8-bit/16-bit PWM selected.
   // Bit6: ECOMn: Comparator Function Enable.
   // Bit5: CAPPn: Capture Positive Function Enable.
   // Bit4: CAPNn: Capture Negative Function Enable.
   // Bit3: MATn: Match Function Enable.
   // Bit2: TOGn: Toggle Function Enable.
   // Bit1: PWMn: Pulse Width Modulation Mode Enable.
   //       0/1:  Disabled/Enabled.
   // Bit0: ECCFn: Capture/Compare Flag Interrupt Enable.
   //       0/1:   Disable/Enable CCFn interrupts.
   PCA0CPL0 = 0x80;    // PCA Counter/Timer Low  Byte.
   PCA0CPH0 = 0x80;    // PCA Counter/Timer High Byte.
}



⌨️ 快捷键说明

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