83 lines
1.9 KiB
Plaintext
83 lines
1.9 KiB
Plaintext
' ########### start ###########
|
|
' pic:PIC16C84
|
|
' ########### end ###########
|
|
'
|
|
' ******************************************************************
|
|
' Tone and PWM demo with 16c84
|
|
' 2014-02-04 (c) Paolo Iocco
|
|
' ******************************************************************
|
|
'
|
|
' Circuit diagram
|
|
' ---------------
|
|
' +--\/--+
|
|
' nc-----|1° 18|-----nc
|
|
' nc-----|2 17|--------->PWM_OUT
|
|
' nc-----|3 16|<--------H
|
|
' +5V--|50K|-->|4 15|<--------H = 4 MHz chrystal+ capacitors
|
|
' GND-------->|5 14|<--------+5V
|
|
' SOUND<------|6 13|-----nc
|
|
' nc-----|7 12|-----nc
|
|
' nc-----|8 11|-----nc
|
|
' nc-----|9 10|-----nc
|
|
' +------+
|
|
'
|
|
' ******************************************************************
|
|
|
|
Config:
|
|
#chip 16C84, 4
|
|
#Config OSC = XT, WDT = OFF, PWRTE = ON, CP = OFF
|
|
'Define Pins and set the pin directions
|
|
#define SoundOut PORTB.0
|
|
#define PWM_out1 PORTA.0
|
|
|
|
'-------------------------------------------------------------
|
|
Startup:
|
|
'-------------------------------------------------------------
|
|
'Main Loop
|
|
Loop:
|
|
Do
|
|
Tone 554, 50
|
|
tone 494, 50
|
|
Tone 440, 50
|
|
tone 494, 50
|
|
Tone 554, 50
|
|
tone 0, 50
|
|
Tone 554, 50
|
|
tone 554, 50
|
|
Tone 494, 50
|
|
tone 0, 50
|
|
Tone 494, 50
|
|
tone 0, 50
|
|
Tone 494, 50
|
|
tone 554, 50
|
|
Tone 659, 50
|
|
tone 0, 50
|
|
Tone 659, 50
|
|
tone 554, 50
|
|
Tone 494, 50
|
|
tone 440, 50
|
|
Tone 494, 50
|
|
tone 554, 50
|
|
Tone 0, 50
|
|
tone 554, 50
|
|
Tone 0, 50
|
|
tone 554, 50
|
|
Tone 494, 50
|
|
tone 0, 50
|
|
Tone 494, 50
|
|
tone 554, 50
|
|
Tone 494, 50
|
|
tone 440, 50
|
|
' PWM Show
|
|
do
|
|
for cnt = 10 to 250 step 10
|
|
PWMOut (1, cnt, 10) 'CHN, Duty, Repeat
|
|
next
|
|
for cnt = 250 to 10 step -10
|
|
PWMOut (1, cnt, 10)
|
|
next
|
|
loop
|
|
loop
|
|
|
|
|