Чт мар 25, 2021 15:31:42
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <stdint.h>
#pragma config FOSC = INTOSC //???????? ?????????? ?????????
#define _XTAL_FREQ 16000000 // Declare crystal frequency to be 16MHZ (for delay functions)
#pragma config WDTE = 00 //????????? ??????
//#pragma config LVP = OFF // Low-Voltage Programming Enable (Low-voltage programming enabled)
//#pragma config LPBOR = OFF // Low-Power Brown Out Reset (Low-Power BOR is disabled)
/*#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = HI // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOR = OFF // Low-Power Brown Out Reset (Low-Power BOR is disabled)
#pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled)
*/
uint8_t countMode=0; //????? ?????????? ??????
uint8_t reqChangeMode=0; //????, ???????????? ????? ????????? ???????? ?????
void InitTimer2(void) //??????? ????????? ??????? 2
{
//static uint8_t statButton;
TOUTPS3 = 1; //Prescaler Out 10
TOUTPS2 = 0;
TOUTPS1 = 0;
TOUTPS0 = 1;
T2CKPS0 = 1;//Postcaler In 16
T2CKPS1 = 0;
PR2 = 0b01111100; //???????????? ???????? ???????
TMR2IE = 1;
TMR2ON = 1;
}
void interrupt isr(void)
{
static uint8_t statButton; //?????????? ????????? ??????
if(TMR2IE&&TMR2IF) //???? ????? ?? ??????????
{
if (RA0) //???? ?????? ????????
{
statButton = ((statButton << 1)|0)&0x3; //??????????? ???????? ?????????? 0
} else //?????
{
statButton = ((statButton << 1)|1)&0x3; //????? 1
}
}
if (statButton == 0b01) //????? ????????? ????????? ??????
{
countMode = (countMode+1)&0x3; //????? ??????
reqChangeMode = 1; //?????? ????????? ??????
}
TMR2IF = 0;
}
/*
*
*/
int main(int argc, char** argv) {
ANSA2 = 0x00; // Set ports as digital I/O, not analog input
ANSA0 = 0x00;
ADCON0 = 0x00; // Shut off the A/D Converter
TRISA0 = 1; // GP0 input
TRISA2 = 0; // GP2 output
PEIE = 1;
GIE = 1;
PWM1EN = 1; //???????? ?????? PWM
PWM1OE = 1;
PWM1POL = 1;
InitTimer2(); //????????? ?????? 2
while(1)
{
LATAbits.LATA2 = 0;
if (reqChangeMode) { //???? ????????? ???????? ?????
reqChangeMode = 0; //???????? ?????????
switch (countMode) { //?????????? ????? ??????
case 0:
{
PWM1DCH = 0x00; //??? ????????
PWM1DCL = 0x0;
PWM1CON = 0xC0;
}
break;
case 1:
{
PWM1DCH = 0x29; //1/3 ????? ????????
PWM1DCL = 0x80;
PWM1CON = 0xC0;
}
break;
case 2:
{
PWM1DCH = 0x53; //2/3 ????? ????????
PWM1DCL = 0x0;
PWM1CON = 0xC0;
}
break;
case 3:
{
PWM1DCH = 0x7C; //?????? ?????????? 1
PWM1DCL = 0xC0;
PWM1CON = 0xC0;
}
break;
}
}
}
}
Чт мар 25, 2021 15:45:57
Чт мар 25, 2021 15:53:05
Чт мар 25, 2021 17:10:34
Чт мар 25, 2021 17:15:02
Чт мар 25, 2021 17:21:07
Спросите у автора этого кода. Он быстрей ответит на этот вопрос.Bondosha писал(а):поэтому и спрашиваю тут как это исправить
Чт мар 25, 2021 17:21:47
Чт мар 25, 2021 17:31:21
Об этом мы должны догадаться ?Bondosha писал(а):на ножке RA0
Кто издевается тут, так это Вы единственный.Bondosha писал(а):хватит издеваться
Чт мар 25, 2021 18:09:56
Чт мар 25, 2021 20:14:37
Чт мар 25, 2021 21:18:08
Чт мар 25, 2021 22:17:32
TOUTPS3 = 1; //Prescaler Out 10
TOUTPS2 = 0;
TOUTPS1 = 0;
TOUTPS0 = 1;
T2CKPS0 = 1;//Postcaler In 16
T2CKPS1 = 0;
PR2 = 0b01111100; //???????????? ???????? ???????
void interrupt isr(void) {
static uint8_t statButton;
if (TMR2IE && TMR2IF) {
if (RA0) {
statButton = ((statButton << 1) | 0) & 0x3;
} else {
statButton = ((statButton << 1) | 1) & 0x3;
}
}
if (statButton == 0b01) {
countMode = (countMode + 1) & 0x3;
reqChangeMode = 1;
}
TMR2IF = 0;
}
void interrupt isr(void) {
static uint8_t statButton;
if (TMR2IE && TMR2IF) {
if (RA0) {
if (statButton < 255)
statButton++;
} else {
if (statButton > 0)
statButton--;
if (statButton >= 50) { // кнопка была нажата > ~51мс
countMode = (countMode + 1) & 0x3;
reqChangeMode = 1;
statButton = 0; // сбросим
}
}
}
TMR2IF = 0;
}
Пн мар 29, 2021 21:36:51
Вт мар 30, 2021 15:12:20