79. User port experimenting (3) ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is a little program to enable you to use your micro as an AF signal generator. The tone is emitted as a 5 Volt p-p squarewave on pin PB7 of the User Port. I suggest you connect a 0.1uF capacitor and a 10k resistor in series with the output, to protect the 6522 VIA chip. The program initially generates 1000 Hz, and you then enter the frequency required. The timing increments available are fairly coarse, especially near the 25kHz end, so the frequency you actually get will not be exactly what you asked for. The maximum frequency possible is 250kHz, but the next increment down is 167kHz, which isn't very helpful! You can hear the tone by connecting a CRYSTAL earphone or microphone insert across the output, or by feeding it into an amplifier. 10 ON ERROR GOTO 80 20 ?&FE6B=&C0:?&FE64=&F2:?&FE65=1:freq%=1000 30 REPEAT:F%=10^6/freq%/2-1.5:?&FE66=F% MOD 256:?&FE67=F% DIV 256 40 actual%=10^6/((F%+2)*2)+0.5 50 PRINT"Generating: ";actual%" Hz"' 60 REPEAT:INPUT"Frequency ? "freq%:UNTIL freq%>49 AND freq%<25001 70 UNTIL FALSE 80 REPORT:PRINT" at line ";ERL:?&FE6B=0