Сб июл 20, 2019 11:03:53
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#pragma config FOSC = INTOSCCLK
#pragma config IOSCFS = 8MHZ // Internal Oscillator Frequency Select bit (8 MHz)
#define _XTAL_FREQ 16000000 // Declare crystal frequency to be 8MHZ (for delay functions)
void rezhim1() {
GPIO2 = 1;
__delay_us(667);
GPIO2 = 0;
__delay_us(1333);
}
void rezhim2() {
GPIO2 = 1;
__delay_us(1333);
GPIO2 = 0;
__delay_us(667);
}
void rezhim3() {
GPIO2 = 1;
}
void rezhim4() {
GPIO2 = 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
while(1)
{
if (GPIO0 == 1)
{
GPIO2 = 0;
} else
{
rezhim1();
}
if (GPIO0 == 1)
{
GPIO2 = 0;
} else
{
rezhim2();
}
if (GPIO0 == 1)
{
GPIO2 = 0;
} else
{
rezhim3();
}
if (GPIO0 == 1)
{
GPIO2 = 0;
} else
{
rezhim4();
}
}
}
}
Сб июл 20, 2019 12:42:49
Сб июл 20, 2019 12:46:50
Сб июл 20, 2019 12:54:17
Вс июл 21, 2019 06:42:11
Вс июл 21, 2019 10:34:44
Вс июл 21, 2019 11:21:36
uint8_t countMode=0;
uint8_t reqChangeMode=0;
// в обработчике прерываний по таймеру - чтение кнопки GP0
static uint8_t statButton;
if (GP0) {
statButton=((statButton<<1)|1)&0x3;
} else {
statButton=((statButton<<1)|0)&0x3;
}
if (statButton == 0b10) {
reqChangeMode=1;
}
// в main-e
if (reqChangeMode) {
reqChangeMode=0;
countMode=(countMode+1)&0x3;
switch (countMode)
case 0: настраиваем режим 0
case 1: настраиваем режим 1
case 2: настраиваем режим 2
case 3: настраиваем режим 3
}
Пн июл 22, 2019 07:40:35
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#pragma config FOSC = INTOSCCLK
#pragma config IOSCFS = 4MHZ // Internal Oscillator Frequency Select bit (8 MHz)
#define _XTAL_FREQ 16000000 // Declare crystal frequency to be 8MHZ (for delay functions)
int statButton = 0b11;
int countMode = 0;
int reqChangeMode = 0;
unsigned char ncnt = 0;
void InitTimer2(void)
{
TOUTPS3 = 1; //Prescaler Out 10
TOUTPS2 = 0;
TOUTPS1 = 0;
TOUTPS0 = 1;
T2CKPS0 = 1;//Postcaler In 16
T2CKPS1 = 1;
PR2 = 0xFF; //TIMER2 Period 255
TMR2IE = 1;
TMR2ON = 1;
}
void interrupt isr(void)
{
if(TMR2IE&&TMR2IF)
{
TMR2IF = 0;
ncnt++;
if(ncnt > 25)
{
ncnt = 0;
}
}
if (GP0)
{
statButton = ((statButton<<1)|1)&0x3;
} else
{
statButton = ((statButton<<1)|0)&0x3;
}
if (statButton == 0b10)
{
countMode = (countMode+1)&0x3;
reqChangeMode = 1;
}
}
unsigned char CheckButton(void)
{
unsigned char result = 0;
unsigned int butcount = 0;
while(GP0)
{
if(butcount < 10000)
{
butcount++;
}
else
{
result = 1;
break;
}
}
return result;
}
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
CCP1IE = 1;
CCP1CON = 0x0F; //PWM mode CCP
InitTimer2();
while(1)
{
if (CheckButton())
{
}
if (reqChangeMode) {
reqChangeMode = 0;
switch (countMode) {
case 0:
{
T2CON = 0b00000111;
CCPR1L = 0b00101001;
CCP1CON = 0b00101100;
}
case 1:
{
T2CON = 0b00000111;
CCPR1L = 0b01010011;
CCP1CON = 0b00011100;
}
case 2:
{
T2CON = 0b00000111;
CCPR1L = 0b01111100;
CCP1CON = 0b00111100;
}
case 3:
{
T2CON = 0b00000111;
CCPR1L = 0b00000000;
CCP1CON = 0b00001100;
}
}
}
}
}
}
Пн июл 22, 2019 09:07:33
Пн июл 22, 2019 09:21:41
Пн июл 22, 2019 09:28:13
Пн июл 22, 2019 09:38:21
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#pragma config FOSC = INTOSCCLK
#pragma config IOSCFS = 4MHZ // Internal Oscillator Frequency Select bit (8 MHz)
#define _XTAL_FREQ 16000000 // Declare crystal frequency to be 8MHZ (for delay functions)
//unsigned char ncnt = 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 int statButton = 0b11;
static int countMode = 0;
static int reqChangeMode = 0;
if(TMR2IE&&TMR2IF)
{
TMR2IF = 0;
if (GP0)
{
statButton = ((statButton << 1)|0)&0x3;
} else
{
statButton = ((statButton << 1)|1)&0x3;
}
if (statButton == 0b01)
{
countMode = (countMode + 1)&0x3;
reqChangeMode = 1;
}
}
}
void setDuty(unsigned int duty) {
CCPR1L = duty >> 2;
CCP1CON &= 0xCF;
CCP1CON |= (0x30 & (duty << 4));
}
int main(int argc, char** argv) {
{
static int statButton = 0b11;
static int countMode = 0;
static int reqChangeMode = 0;
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
CCP1IE = 1;
InitTimer2();
while(1)
{
if (reqChangeMode) {
reqChangeMode = 0;
switch (statButton) {
case 0:
{
//setDuty(33.35);
T2CON = 0b00000111;
CCPR1L = 0b00101001;
CCP1CON = 0b00101100;
}
case 1:
{
//setDuty(66.65);
T2CON = 0b00000111;
CCPR1L = 0b01010011;
CCP1CON = 0b00011100;
}
case 2:
{
//setDuty(100);
T2CON = 0b00000111;
CCPR1L = 0b01111100;
CCP1CON = 0b00111100;
}
case 3:
{
//setDuty(0);
T2CON = 0b00000111;
CCPR1L = 0b00000000;
CCP1CON = 0b00001100;
}
}
}
}
}
}
Пн июл 22, 2019 09:56:08
Пн июл 22, 2019 09:56:57
#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 16000000 // 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)
{
uint8_t statButton=0b11;
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) {
{
uint8_t statButton=0b11;
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
CCP1IE = 1;
InitTimer2();
while(1)
{
if (reqChangeMode) {
reqChangeMode = 0;
switch (statButton) {
case 0:
{
T2CON = 0b00000111;
CCPR1L = 0b00101001;
CCP1CON = 0b00101100;
}
case 1:
{
T2CON = 0b00000111;
CCPR1L = 0b01010011;
CCP1CON = 0b00011100;
}
case 2:
{
T2CON = 0b00000111;
CCPR1L = 0b01111100;
CCP1CON = 0b00111100;
}
case 3:
{
T2CON = 0b00000111;
CCPR1L = 0b00000000;
CCP1CON = 0b00001100;
}
}
}
}
}
}
Пн июл 22, 2019 10:10:26
Пн июл 22, 2019 10:25:00
#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 16000000 // 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=0b11;
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) {
{
uint8_t statButton=0b11;
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
CCP1IE = 1;
InitTimer2();
while(1)
{
if (reqChangeMode) {
reqChangeMode = 0;
switch (statMode) {
case 0:
{
T2CON = 0b00000111; // общая часть - вынести в инициализацию
CCPR1L = 0b00101001;
CCP1CON = 0b00101100;
}
case 1:
{
T2CON = 0b00000111;
CCPR1L = 0b01010011;
CCP1CON = 0b00011100;
}
case 2:
{
T2CON = 0b00000111;
CCPR1L = 0b01111100;
CCP1CON = 0b00111100;
}
case 3:
{
T2CON = 0b00000111;
CCPR1L = 0b00000000;
CCP1CON = 0b00001100;
}
}
}
}
}
}
Пн июл 22, 2019 10:44:20
Пн июл 22, 2019 11:08:33
#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 16000000 // 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=0b11;
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) {
{
uint8_t statButton=0b11;
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
CCP1IE = 1;
InitTimer2();
PEIE=1;
GIE=1;
while(1)
{
if (reqChangeMode) {
reqChangeMode = 0;
switch (statMode) {
case 0:
{
T2CON = 0b00000111; // общая часть - вынести в инициализацию
CCPR1L = 0b00101001;
CCP1CON = 0b00101100;
}
case 1:
{
T2CON = 0b00000111;
CCPR1L = 0b01010011;
CCP1CON = 0b00011100;
}
case 2:
{
T2CON = 0b00000111;
CCPR1L = 0b01111100;
CCP1CON = 0b00111100;
}
case 3:
{
T2CON = 0b00000111;
CCPR1L = 0b00000000;
CCP1CON = 0b00001100;
}
}
}
}
}
}
Пн июл 22, 2019 11:13:00
Пн июл 22, 2019 11:22:22