|
以下是刚写的,仿真通过,由于接触bascom才三天,不对的地方望指教!
'/////////////////////////////////////////////////////////
'/// 以下是timer0的输出比较中断程序 ///
'/// 每过1ms中断一次,pina.1控制led闪烁 ///
'/////////////////////////////////////////////////////////
$Device= m16 ' 定义器件
$Stack = 120 ' 定义堆栈大小
$Clock = 8 ' 定义时钟频率
$Def led=PORTA.0 ' 端口定义
$Timer0=Timer,Prescale=64,Compare= Reset,Clear '定义timer0
Declare Interrupt Oc0() ' 定义oc0中断
DDRA.0=1 ' 定义io口
DDRA.1=0
PORTA.0=1
PORTA.1=1
Dim count0 As Byte ' 定义变量
count0=0 ' 清零count0
Stop Timer0 ' timer0停止
ocr0=&h7d ' 置ocr0初值
tcnt0=0 ' tcnt0清零
Enable Oc0 ' 打开oc0中断
Enable Interrupts ' 打开全局中断
Do ' 进入主程序
If PINA.1=1 Then ' pina.1状态控制oc0中断
Start Timer0
Else
Set led ' led和计数器还原为初始状态
Stop Timer0
count0=0
tcnt0=0
End If
Loop
End
Interrupt Oc0(),Save 1 ' oc0中断程序
Incr count0 ' count0加1
If count0>=250 Then
Toggle led:count0=0 ' led每过250ms变化一次
End If
End Interrupt ' oc0中断结束 |
|