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

📄 mcu.c

📁 使用于克隆器
💻 C
字号:
// Common
#include "define.h"
#include "mcu.h"
#include "board.h"
#include "global.h"
#include "common.h"
#include "userdef.h"
// External
#include "debug.h"
#include "userpref.h"

// Internal
#include "uart.h"

void LEDFlash(void)
{
    if(_bit0_(LED_POWER))ClrLed_POWER();
    else SetLed_POWER();
}

void LEDReadFlash(void)
{
    if(_bit0_(LED_READING))ClrLed_READING();
    else SetLed_READING();
}

void LEDWriteFlash(void)
{
    if(_bit0_(LED_WRITING))ClrLed_WRITING();
    else SetLed_WRITING();
}


void LEDFlashDelay(BYTE num)
{
    if(num<=0)num=1;
    do
    {
        LEDFlash();
        num--;
        Delay1ms(500);
        //printf("\r\n  %d", num);
    }while(num);
}


#ifdef MCU_MTV412M
BOOL Enter_MTV412_ISP(void)
{
    ES = 1;                      // Disable uart interrupt

    PADMOD2 = 0x87;//P4.0~P4.2 I/O,BIT7 =>iic ,P3.4&P3.5 I/O,OTHER PWM
    SLVBADDR = 0xA6;

    IE = 0;
    WDT = 0;
    ISPSLV = 0x7C; // ISP Slave address
    ISPEN = 0x93; // Enable MTV312 ISP function
    PCON = 0x01; // MCU Idle mode
    while (1);
    return TRUE;
}
#endif

#if 0
void mcuCheckISPWhenPowerUp(void)
{
    BYTE tmp1,tmp2;
    tmp1=tmp2=255;
    MADC = 0x82;//AD1
    Delay1ms(2);
    tmp1 = MADC;
    MADC = 0x81;//AD0
    Delay1ms(2);
    tmp2 = MADC;
    if ((tmp1 <= (0x24+15)) && (tmp2 <= (0x59+15)))
    {//         CH+                      V0l-
        putstr("ISP Now");
        Enter_MTV412_ISP();
    }
}
#endif
void McuInit(void)
{
    
#ifdef MCU_MTV412M
    //PIN config
    //Note:P4 is output only!
    PADMOD0 = 0x04; //P6 setting ,P6.2is AD, P6.0~P6.1,P6.3~P6.7 is general I/O,20060513
    PADMOD1 = 0x7F; //P5 setting ,P5.0~P5.6  I/O
    PADMOD2 = 0x07; //P4.0~P4.2 I/O,P3.0&P3.1 RS232 ,P3.4&P7.7 I/O,
    //P7.5&P7.6 I/O,OTHER PWM
    PADMOD3 = 0x20; //P5 setting ,P5.5 Output,P5.0~P5.4,P5.6 input,20060513
    PADMOD4 = 0xFB; //P6 setting ,P6.2 input, P6.0~P6.1,P6.3~P6.7 output,20060513
    PADMOD5 = 0x00; //P1 setting ,P1 8051 standard I/O
    PADMOD6 = 0x17; //P7 setting ,P7.0,P7.1,P7.2,P7.4 I/O;  P7.3 Hsync
    PADMOD7 = 0xF4; //P7 setting ,P7.7~P7.4,P7.2 Output;  P7.3,P7.1~P7.0 Input
    g_PadMod7 = 0xF4;
    //other option
    INTEN = 0x00;  //not Enable  Recive B interrupt //0x40->enable isp
    HVINTEN = 0x00; //not Enable H V sync interrupt
    WDT = 0x00; //not Enable Watchdog timer
    SLVBADDR = 0xA6;
    OPTION = 0x60; //0x20->double speed ,253 step

    P3_2 = 1; // INT0 IR
    IE0 = 0;
    P1 = 0xff;//keyboard and panel select
    HVCTR0 = 0x40;//0xc0;//MCU HSync Input type CSync
    HVCTR2 = 0x00;//0x30
    HVCTR3 = 0x78;
    HVCTR4 = 0x00;
#endif

#ifdef MCU_W78E65
    CHPENR = 0x87; // enable CHPCON register write attribute
    CHPENR = 0x59; // enable CHPCON register write attribute
    CHPCON = 0x18; // disable all control function(enable AUX-RAM)
    CHPENR = 0x00; // disable CHPCON write attribute
#endif

#ifdef MCU_W77E532
    SetBankSwitchPin();
    PMR = (PMR | _BIT0) & (~_BIT2);
    CKCON = 0x03;
#endif
    uartInitialize(); // initialze uart
    //gVersionMessage(); // version message

#if ( BOARD_TYPE_SEL == BD_SHENZHEN_DEMO )
    //mcuCheckISPWhenPowerUp();
#endif

    isrInitializeInterrupt(); // initialize MCU interrupt
    usrCheckEEPROM(); // check EEPROM reset
    InitVariable(); // intialize global variable
}

void PowerOnInitial(void)
{
    LEDFlashDelay(5);
    LEDFlash();

    LEDFlash();
    LEDFlash();


    LEDFlash();

    SetLed_POWER();//msLEDG_PIN = 1;
}

//Copy data TV Ram -> Mcu Ram
void GetDataTV_McuRam(void)
{
}
//Copy data Mcu Ram -> TV Ram
void GetDataMcuRam_TV(void)
{
}


⌨️ 快捷键说明

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