?? main.c~
字號:
/*********************************************
Project : Music
Version : V1.1
Date : 08.06.2001
Author : Holger Buss
http://www.mikrocontroller.com
Chip type : AT90S8535 or AT90S8535
Clock frequency : 8,000000 MHz
Memory model : Small
Internal SRAM size : 512
External SRAM size : 0
Data Stack size : 128
*********************************************/
#include <90s8535.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15
#endasm
#include <lcd.h>
#include <delay.h>
#include <stdio.h>
// Declare your global variables here
#define Taste1 PINA.7
#define Taste2 PINA.6
#define Taste3 PINA.5
#define Taste4 PINA.4
#define Taste5 PINA.3
#include "Ton.c"
unsigned char T1Reload;
bit Play;
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Reinitialize Timer's 0 value
TCNT0 = T1Reload;
if(T1Reload != Silence && Play)
{
if(Taste2) PORTB.4 = !PORTB.4; // Relais
else PORTB.3 = !PORTB.3; // Speaker
}
else
{
PORTB.3 = 0;
PORTB.4 = 0;
}
}
// Timer 2 overflow interrupt service routine
interrupt [TIM2_OVF] void timer2_ovf_isr(void)
{
// Reinitialize Timer's 2 value
// TCNT2 = T2Reload;
// Place your code here
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
char txt[16];
unsigned char t,x;
int Speed = 6;
unsigned char Song = 0;
t=0x80;
x=0x40;
// Input/Output Ports initialization
// Port A
PORTA=0x00;
DDRA=0x00;
// Port B
PORTB=0x00;
DDRB=0x1f;
// Port C
PORTC=0x00;
DDRC=0x00;
// Port D
PORTD=0x00;
DDRD=0b11000000;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 125,000 kHz
// Mode: Output Compare
// OC0 output: Disconnected
TCCR0=0x03;
TCNT0=0x30;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Output Compare
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: 125,000 kHz
// Mode: Pulse Width Modulation
// OC2 output: Inverted PWM
TCCR2=0x00;
ASSR=0x00;
TCNT2=0x80;
OCR2=0x40;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
GIMSK=0x00;
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x41;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
// LCD module initialization
lcd_init(16);
// Global enable interrupts
#asm("sei")
Play = 1;
lcd_init(16);
while (1)
{
unsigned char index;
unsigned int lang;
if(Taste1) { Song++; index = 0; Play = 1; delay_ms(200);};
if(Taste2) TCCR0 = 0x02; // one octave higher (double Timer frequency)
else TCCR0 = 0x03; // Standart octave
if(Taste3) Speed++;
if(Taste4) if(Speed > 1) Speed--;
if(Taste5) { Play = 1;};
if(!Play) index = 0;
// prepare the display
lcd_clear();
lcd_gotoxy(2,1);
switch(Song)
{
case 0:
// end of Song?
if(index >= WARS_LAENGE) { Play = 0;};
// set the frequency
T1Reload = WarsSong[index][0];
// duration of this tone
lang = WarsSong[index][1] * Speed;
lcd_putsf("Star Wars");
break;
case 1:
if(index >= AXEL_LAENGE) { Play = 0;};
T1Reload = AxelSong[index][0];
lang = AxelSong[index][1] * Speed;
lcd_putsf("Axel F");
break;
case 2:
if(index >= HAYDN_LAENGE) { Play = 0;};
T1Reload = HaydnSong[index][0];
lang = HaydnSong[index][1] * Speed;
lcd_putsf("Haydn");
break;
case 3:
if(index >= VOY_LAENGE) { Play = 0;};
T1Reload = VoySong[index][0];
lang = VoySong[index][1] * Speed;
lcd_putsf("Voyager");
break;
case 4:
if(index >= BOND_LAENGE) { Play = 0;};
T1Reload = BondSong[index][0];
lang = BondSong[index][1] * Speed;
lcd_putsf("James Bond");
break;
case 5:
if(index >= BABY_LAENGE) { Play = 0;};
T1Reload = BabySong[index][0];
lang = BabySong[index][1] * Speed;
lcd_putsf("Baby Girl");
break;
default: Song = 0;
break;
}
// Set '*'
lcd_gotoxy(T1Reload / 12,0);
lcd_putsf("*");
// show index
sprintf(txt,"%2d",index);
lcd_gotoxy(13,1);
lcd_puts(txt);
// wait for the duration of this tone
for(lang;lang;lang--)
{
delay_ms(25);
}
// next tone
index++;
// make a pause between the tones
T1Reload = Silence;
delay_ms(20);
};
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -