这个代码是直接操作io地址空间的,应该在用户态也是可以运行的(没试过,不确定)。我查了下0x61端口的描述
PB7 0 enable keyboard read
1 clear keyboard and enable sense of SW1
PB6 0 hold keyboard clock low, no shift reg. shifts
1 enable keyboard clock signal
PB5 0 enable i/o check
1 disable i/o check
PB4 0 enable r/w memory parity check
1 disable r/w parity check
PB3 0 turn off LED
1 turn on LED (old cassettee motor off)
PB2 0 read spare key
1 read r/w memory size (from Port C)
PB1 0 turn off speaker
1
enable speaker data
PB0 0 turn off timer 2
1 turn on timer 2,
gate speaker with square wave
是不是speaker不仅跟PB1有关,还和PB0有关呢?
楼主可以做下实验试试。