微處理器 - Lattice GAL22V10 - C/C++ - Timer0



參考資訊:
https://www.stcmicro.com/datasheet/STC15F204EA-cn.pdf
https://www.stcmicro.com/datasheet/STC15F2K60S2-en.pdf

AUXR


TMOD


TCON


Interrupt


main.c

#include <mcs51/8051.h>

__sfr __at(0x8E) AUXR;

#define LED P1_2

void t0_isr(void) __interrupt 1
{
    static int cnt = 0;
 
    cnt += 1;
    if (cnt > 255) {
        cnt = 0;
        LED ^= 1;
    }
}
  
int main(void)
{
    AUXR |= 0x80;
    TMOD = 0x00;
    TL0 = 0x00;
    TH0 = 0x00;
    TR0 = 1;
    ET0 = 1;
    EA = 1;
 
    LED = 1;
    while (1) {
    }
  
    return 0;
}

完成