#include <16F628.h>
#use delay(clock=4000000)
#fuses XT,PUT,BROWNOUT,MCLR,NOWDT,NOPROTECT,NOLVP
//PIC16F6X8
#define PORTA 0x05
//Sound
#define Speaker PORTA //Speaker Port
#define Spkbit 0B00000001 //Speaker bit is RA0
//Sound
void Sound(char freq,char dura);
void SoundOK(void);
void SoundAdmin(void);
void SoundFn(void);
void SoundERR(void);
void SoundSuccess(void);
void SoundNext(void);
void SoundHL(void);
//*** Sound ***
//Working send out put to toggle Spkbit
//XTAL 4MHz
void Sound(char freq,char dura)
{
int dl,cl;
#asm
MOVLW 50
MOVWF dl
SndNx:
MOVF freq,W
MOVWF cl
MOVLW Spkbit
XORWF Speaker,F
SndLp:
NOP
NOP
NOP
DECFSZ cl,F
GOTO SndLp
DECFSZ dl,F
GOTO SndNx
MOVLW 50
MOVWF dl
DECFSZ dura,F
GOTO SndNx
#endasm
}
//@sound
void SoundAdmin(void)
{
Sound(25,30);
delay_ms(50);
Sound(25,10);
delay_ms(50);
Sound(25,10);
}
void SoundOK(void)
{
Sound(25,20);
}
void SoundHL(void)
{
Sound(25,75);
}
void SoundFn(void)
{
Sound(20,15);
}
void SoundERR(void)
{
Sound(210,10);
}
void SoundSuccess(void)
{
Sound(25,10);
delay_ms(50);
Sound(25,10);
delay_ms(50);
Sound(25,10);
}
void SoundNext(void)
{
Sound(25,10);
delay_ms(50);
Sound(25,10);
}
//*** MAIN ***
void main()
{
SET_TRIS_A(0B11111110);
SoundSuccess();
delay_ms(500);
SoundOK();
delay_ms(500);
SoundAdmin();
delay_ms(500);
SoundFn();
delay_ms(500);
SoundERR();
delay_ms(500);
SoundNext();
delay_ms(500);
SoundHL();
} |