📄 flash.c
字号:
/* FLASH.C - LED Flasher for the Forth EVA 167 Board with C167CR_2 Module */
#include <reg167.h>
#include <stdio.h>
#include <intrins.h>
unsigned int t2_count = 0;
void wait (unsigned long delay) { /* wait function */
unsigned long cl;
for (cl=0; cl <= delay; cl++)
_nop_();
}
void main (void) {
unsigned int i; /* Delay var */
unsigned int j; /* LED var */
T2CON = 0x04; // prescaler = fCPU/128
T2IC = 0x51; // enable T2 Interrrut, IL=2, GL=1
T2R = 0; // stop Timer 2
IEN = 1; // global Interrupt enable
DP2 = 0x00FF;
ODP2 = 0x0000;
// do not use printf for Simulated Serial Interface!!
printf("Sorry, no LEDs available on the Forth EVA 167 board..\n");
while (1) { /* Loop forever */
//T2R = 1; /* run Timer 2 */
for (j=0x0100; j != 0; j<<=1){ /* Blink LED */
P2 = ~j & 0x00FF; /* Output to LED Port */
for (i = 0; i < 10000; i++) { /* Delay for 10000 Counts */
wait (0); /* call wait function */
}
}
for (j=0x8000; j>0x0080; j>>=1){ /* Blink LED */
P2 = ~j & 0x00FF; /* Output to LED Port */
for (i = 0; i < 10000; i++) { /* Delay for 10000 Counts */
wait (0); /* call wait function */
}
}
}
}
void T2_ISR (void) interrupt 0x22 {
T2R = 0; /* stop Timer 2 */
T2 = 0; /* reset Timer 2 */
P1L = 0; /* Output to LED Port */
wait(0x10000); /* wait for some time */
printf("\rTimer2 Interrupt counter: %04D",t2_count++);
T2R = 1; /* Start Timer 2 */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -