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

📄 cpu_c515a.c

📁 Small Device C Compiler 面向Inter8051
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Input       : char Byte                                          *//*------------------------------------------------------------------*//* Returnvalue : none                                               *//*------------------------------------------------------------------*//* History     : 00/03    V1.0 Initial Version                      *//*                                                                  *//********************************************************************/void putchar(  char Byte ){    while( !TI ) /* wait for TI==1 */    {        WatchDog();        CpuIdle();    }    SBUF = Byte;    TI = 0;}/********************************************************************//* Function    : getchar()                                      SUB *//*------------------------------------------------------------------*//* Description : everybody knows what this function is doing        *//*------------------------------------------------------------------*//* Author      : Michael Schmitt                                    *//*------------------------------------------------------------------*//* Input       : none                                               *//*------------------------------------------------------------------*//* Returnvalue : char Byte                                          *//*------------------------------------------------------------------*//* History     : 00/03    V1.0 Initial Version                      *//*                                                                  *//********************************************************************/char getchar( void ){    while( !RI ) /* wait for RI==1 */    {        WatchDog();        CpuIdle();    }    RI=0;    return (SBUF);}/********************************************************************//* Function    : keypressed()                                   SUB *//*------------------------------------------------------------------*//* Description : is a char available ?                              *//*------------------------------------------------------------------*//* Author      : Michael Schmitt                                    *//*------------------------------------------------------------------*//* Input       : none                                               *//*------------------------------------------------------------------*//* Returnvalue : TRUE yes, FALSE no                                 *//*------------------------------------------------------------------*//* History     : 00/03    V1.0 Initial Version                      *//*                                                                  *//********************************************************************/char keypressed( void ){    unsigned char c;    if(RI)    {        c = TRUE;    }    else    {        c = FALSE;    }    return (c);}#endif// ===========================================================================// System Timer#ifdef USE_SYSTEM_TIMERvolatile unsigned long SystemTicks1msec;// Here are the definitions of the 1kHz Timer 0// used for delay( xx_msec )#ifndef CPUCLKHZ#error "CPUCLKHZ is not defined !"#endif#define TIMER0INTSPERSECOND     1000#define TIMER0MODE1RELOADVALUE  (-((CPUCLKHZ/TIMER0INTSPERSECOND)/12))/********************************************************************//* Function    : delayMsec()                                    SUB *//*------------------------------------------------------------------*//* Description : waste some CPU-Time, CPU will be set into IDLE Mode*//*               and is waked up every 1msec by TIMER0              *//*------------------------------------------------------------------*//* Author      : Michael Schmitt                                    *//*------------------------------------------------------------------*//* Input       : unsigned long delayTime                            *//*------------------------------------------------------------------*//* Returnvalue : none                                               *//*------------------------------------------------------------------*//* History     : 99/10    V1.0 Initial Version                      *//*                                                                  *//********************************************************************/void DelayMsec( unsigned long delayTime ){    delayTime += SystemTicks1msec;    WatchDog();    while( SystemTicks1msec < delayTime )    {        CpuIdle();        WatchDog();    }    WatchDog();}/********************************************************************//* Function    : timer0_isr                                     ISR *//*------------------------------------------------------------------*//* Description : This ISR is called every 1msec and inc. a variable *//*               that is used for delay()                           *//*------------------------------------------------------------------*//* Author      : Michael Schmitt                                    *//*------------------------------------------------------------------*//* Input       : none                                               *//*------------------------------------------------------------------*//* Returnvalue : none                                               *//*------------------------------------------------------------------*//* History     : 99/10    V1.0 Initial Version                      *//*                                                                  *//********************************************************************/void timer0_isr (void) interrupt TF0_VECTOR{    /* Interruptrate will be slightly slower than wanted */    /* because TL0 is not 0 here, not bug-fix yet */    TL0 = (TIMER0MODE1RELOADVALUE & 0x00FF);    TH0 = (TIMER0MODE1RELOADVALUE >> 8);    SystemTicks1msec++;}#endif // USE_SYSTEM_TIMER// ===========================================================================// Analog Stuff#ifdef USE_ANALOGPORTunsigned int ADCGetValue( char ADCPort ){    // if a conversion is busy, wait    while( BSY )    {        //    }    WatchDog();    // set AD-Port    ADCON1 &= 0xF8;             // clear MX0 to MX2    ADCON1 |= (ADCPort & 0x07); // set Port    // start AD Conversion    ADDATL = 0x00;    while( BSY )    {        //    }    WatchDog();    // read AD Converter Register    return( (((unsigned int)ADDATH) << 2) + ((unsigned int)ADDATL >> 6) );}#endif// ===========================================================================// ===================================================================// Global Hardware Init/********************************************************************//* Function    : InitHardware()                                 SUB *//*------------------------------------------------------------------*//* Description : Should be the first executed after reset to get a  *//*               proper initalised CPU                              *//*------------------------------------------------------------------*//* Author      : Michael Schmitt                                    *//*------------------------------------------------------------------*//* Input       : none                                               *//*------------------------------------------------------------------*//* Returnvalue : none                                               *//*------------------------------------------------------------------*//* History     : 99/10    V1.0 Initial Version                      *//*                                                                  *//********************************************************************/void InitHardware( void ){#ifdef USE_SYSTEM_TIMER    SystemTicks1msec = 0x0;#endif // USE_SYSTEM_TIMER    EA = 0;         // Disable ALL Ints    ES = 0;         // Disable Serial Int    ET1 = 0;        // Disable Timer 1 Int    EX1 = 0;        // Disable External Interrupt 1    ET0 = 0;        // Disable Timer 0 Int    EX0 = 0;        // Disable External Interrupt 0    EADC = 0;       // Disable A/D Converter Interrupt    TR1 = 0;        // Stop Timer 1    TR0 = 0;        // Stop Timer 0    // The Siemens CPU C515A has 8 Analog inputs with 10Bit resolution    // Conversion Clock is generated from CPU-Clock but should be less    // than max 2MHZ.    if( CPUCLKHZ < 16000000 )    {        // CPU Speed < 16MHz Prescaler Ratio is divide by 4 (Reset default)        ADCON1 &= ~ADCON1_ADCL;        // the automatic A/D Converter Calibration needs        // Reset Calibration phase = 26624 / CPUCLKHZ        // @ 16MHz this is about 1,7msec        // or 2219 machine cycle    }    else    {        // CPU Speed > 16MHz Prescaler Ratio is divide by 4 (Reset default)        ADCON1 |= ADCON1_ADCL;        // the automatic A/D Converter Calibration needs        // Reset Calibration phase = 53248 / CPUCLKHZ        // @ 246MHz this is about 2,3msec        // or 4438 machine cycle    }    // AD-Conversion stars intern and not with P40 ADST#    ADCON0 &= ~ADCON0_ADM;#ifdef USE_SYSTEM_TIMER    // Init Timer 0 as Software Interrupt for 1mSec Timer    TL0 = (TIMER0MODE1RELOADVALUE & 0x00FF);    TH0 = (TIMER0MODE1RELOADVALUE >> 8);    TMOD &= 0xf0;    TMOD |= 0x01;       // Setting Timer 0 als GATE=0 TIMER und MODE 1 16-bit Timer mode    TR0  = 1;           // Enabling Timer 0    TR0 = 1;            // Start Timer 0    ET0 = 1;            // Enable Timer 0 Interrupt#endif#ifdef SERIAL_VIA_INTERRUPT    // Ringbuffer for Serielle UART  init    SERIAL_VIA_INTERRUPT_RCNT = 0;    SERIAL_VIA_INTERRUPT_XCNT = 0;    SERIAL_VIA_INTERRUPT_RPOS = 0;    SERIAL_VIA_INTERRUPT_XPOS = 0;    SERIAL_VIA_INTERRUPT_BUSY = 0;#endif#ifdef SERIAL_IS_DEFINED#ifdef BAUDRATEGENENATOR_USED    // We use the internal Bauratengenerator of the Siemens CPU    SRELL = (BAUDRATEGENRELOADVALUE & 0x00FF);    SRELH = (BAUDRATEGENRELOADVALUE >> 8);    ADCON0 |= 0x80; // set BD-Bit, we use internal Baudrate gen.    PCON |= 0x80;   // SMOD-Bit forr double Baudrate#else    // use TIMER1 im Mode 2    PCON |= 0x80;   // set SMOD-Bit for double Baudrate    TH1 = TIMER1MODE2RELOADVALUE;    TL1 = TIMER1MODE2RELOADVALUE;    TMOD &= 0x0f;    TMOD |= 0x20;   // Timer 1 als GATE=0 TIMER und MODE 2 8-bit auto reload    TR1  = 1;       // Enabling Timer 1#endif    SCON  = 0x40;       // Init Serial Port as 8-Bit UART    SCON |= 0x10;       // Enabling Seriel receive REN-Bit    SCON |= 0x02;       // Setting TI-Bit#ifdef SERIAL_VIA_INTERRUPT        ES = 1;         // Enable Serial Interrupt#endif#endif#ifdef USE_CPU_Internal_XRAM    // CPU Internal SRAM einable    SYSCON = ((SYSCON) & ((UBYTE)~(XMAP0_BIT | XMAP1_BIT)));#endif    EA = 1;             // Enable all Enabled Interrupts}#endif

⌨️ 快捷键说明

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