Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <hidef.h> /* for EnableInterrupts macro */
- #include "derivative.h" /* include peripheral declarations */
- #define LED_1 PTDD_PTDD4
- #define LED_2 PTDD_PTDD5
- #define LED_3 PTDD_PTDD6
- #define LED_4 PTDD_PTDD7
- #define button_1_isPressed !PTAD_PTAD2
- #define button_2_isPressed !PTAD_PTAD3
- #define button_3_isPressed !PTAD_PTAD4
- #define button_4_isPressed !PTAD_PTAD5
- #define Clock_Source TPM1SC_CLKSA
- #define Timer_Register TPM1SC
- #define Timer_Channel_Register TPM1C0SC
- #define ON 0
- #define OFF 1
- #define FIXED 1;
- #define FLASHING 0;
- int delay = 0;
- interrupt VectorNumber_Vtpm1ch0 void step(void)
- {
- if(TPM1C0SC_CH0F)
- TPM1C0SC_CH0F = 0;//встановлення значення флагу в 0 - скидання
- LED_1 = !LED_1; //якщо горіла - не горить. якщо не горіла - горить. Реалізація блимання
- TPM1SC_TOF = 0;//встановлення значення флагу переповненння таймера в 0 - скидання
- }
- void main(void) {
- EnableInterrupts;
- /* include your code here */
- PTDDD = 0b11110000;
- PTDD = 0b11110000;
- PTAPE_PTAPE2 = 1;
- PTAPE_PTAPE3 = 1;
- PTAPE_PTAPE4 = 1;
- PTAPE_PTAPE5 = 1;
- KBIPE_KBIPE5 = 1;
- KBIPE_KBIPE4 = 1;
- KBIPE_KBIPE3 = 1;
- KBIPE_KBIPE2 = 1;
- KBISC_KBIE = 1;// enable Keyboard Interrupts
- KBISC_KBF = 1;
- Timer_Register = 0;
- TPM1C0V = 0;
- TPM1MOD = 50000;
- TPM1CNTH = 0;
- for(;;){
- __RESET_WATCHDOG(); /* feeds the dog */
- } /* loop forever */
- /* please make sure that you never leave main */
- }
- void Btn3Clicked() {
- int frequency = Timer_Register & 0b00000111;
- if(frequency)
- frequency -= 1;
- TPM1SC_PS0 = frequency & 1;
- TPM1SC_PS1 = (frequency >> 1) & 1;
- TPM1SC_PS2 = (frequency >> 2) & 1;
- }
- void Btn1Clicked() {
- TPM1SC_PS2 = TPM1SC_PS1 = TPM1SC_PS0 = 1;
- Timer_Channel_Register = 0;
- TPM1C0SC_CH0IE = TPM1C0SC_MS0A = 1;
- Clock_Source = 1;
- TPM1SC_TOIE = 1;
- }
- void Btn4Clicked(){
- int frequency = Timer_Register & 0b00000111;
- if(frequency != 0b00000111)
- frequency += 1;
- TPM1SC_PS0 = frequency & 1;
- TPM1SC_PS1 = (frequency >> 1) & 1;
- TPM1SC_PS2 = (frequency >> 2) & 1;
- }
- //turn off the blaming
- void Btn2Clicked() {
- Clock_Source = 0;
- Timer_Channel_Register = 0;
- LED_1 = OFF;
- }
- interrupt VectorNumber_Vkeyboard1 void click(void)
- {
- KBISC_KBACK = 1;
- if(button_1_isPressed)
- Btn1Clicked();
- if(button_2_isPressed)
- {
- Btn2Clicked();
- }
- if (button_3_isPressed)
- {
- Btn3Clicked();
- }
- if (button_4_isPressed)
- {
- Btn4Clicked();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement