Пн июл 22, 2019 11:23:49
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <stdint.h>
#pragma config FOSC = INTOSCCLK
#pragma config IOSCFS = 4MHZ // Internal Oscillator Frequency Select bit (8 MHz)
#define _XTAL_FREQ 20000000 // Declare crystal frequency to be 8MHZ (for delay functions)
uint8_t countMode=0;
uint8_t reqChangeMode=0;
void InitTimer2(void)
{
TOUTPS3 = 1; //Prescaler Out 10
TOUTPS2 = 0;
TOUTPS1 = 0;
TOUTPS0 = 1;
T2CKPS0 = 1;//Postcaler In 16
T2CKPS1 = 1;
PR2 = 0b01111100;
TMR2IE = 1;
TMR2ON = 1;
}
void interrupt isr(void)
{
static uint8_t statButton;
if(TMR2IE&&TMR2IF)
{
if (GP0)
{
statButton = ((statButton << 1)|0)&0x3;
} else
{
statButton = ((statButton << 1)|1)&0x3;
}
if (statButton == 0b01)
{
countMode = (countMode+1)&0x3;
reqChangeMode = 1;
}
TMR2IF = 0;
}
}
int main(int argc, char** argv) {
{
ANSEL = 0x00; // Set ports as digital I/O, not analog input
ADCON0 = 0x00; // Shut off the A/D Converter
TRISIO0 = 1; // GP3 input, rest all output
TRISIO2 = 0;
GPIO = 0x00; // Make all pins 0
PEIE=1;
GIE=1;
InitTimer2();
T2CON = 0b00000111;
while(1)
{
if (reqChangeMode) {
reqChangeMode = 0;
switch (countMode) {
case 0:
{
CCPR1L = 0b00101001;
CCP1CON = 0b00101100;
}
case 1:
{
CCPR1L = 0b01010011;
CCP1CON = 0b00011100;
}
case 2:
{
CCPR1L = 0b01111100;
CCP1CON = 0b00111100;
}
case 3:
{
CCPR1L = 0b00000000;
CCP1CON = 0b00001100;
}
}
}
}
}
}
Пн июл 22, 2019 12:37:06
Пн июл 22, 2019 12:41:28
Пн июл 22, 2019 12:45:57
Пн июл 22, 2019 12:53:20