Вт май 10, 2022 19:34:54
/*
* File: main.c
* Author: Roo
*
* Created on 8 ??? 2022 ?., 11:29
*/
#include <stdio.h>
#include <stdlib.h>
/*
*
*/
// CONFIG
#pragma config FOSC = INTRCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // Power-Up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = ON // GP3/MCLR pin function select (GP3/MCLR pin function is MCLR)
#pragma config BOREN = ON // Brown-out Detect Enable bit (BOD enabled)
#pragma config CP = OFF // Code Protection bit (Program Memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#define _XTAL_FREQ 4000000 // Fosc frequency for _delay() library
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
int main(int argc, char** argv) {
ANSEL = 0b00000000;
ADCON0 = 0b00000000;
nGPPU = 0b00000000;
WPU = 0b00000000;
TRISIO = 0b00001111;
GPIO = 0b00000000;
GIE = 0;
unsigned char Q = 0; //start status
while (1)
{
if (GPIO2) {
GPIO4 = 0;
GPIO5 = 1;
__delay_ms(500);
GPIO5 = 0;
__delay_ms(500); }
else if (!GPIO0 && GPIO1) {
GPIO4 = 0;
GPIO5 = 1; }
else if (GPIO0 && GPIO1) {
GPIO4 = 0;
GPIO5 = 0;
Q = 1; }
else if ((!GPIO0 && !GPIO1) || (GPIO0 && !GPIO1 && !Q)) {
GPIO4 = 1;
GPIO5 = 0;
Q = 0; }
}
return (EXIT_SUCCESS);
}
void main()
{
unsigned char Q=0; /*start status */
ANSEL = 0b00000000;
ADCON0 = 0b00000000;
/* GPPU = 0b00000000; */
WPU = 0b00000000;
TRISIO = 0b00001111;
GPIO = 0b00000000;
/* GIE = 0; */
while (1)
{
if (GPIO.GP2) {
// GPIO.GP4 = 0;
GPIO.GP4 = 0;
GPIO.GP5 = 1;
Delay_ms(500);
GPIO.GP5 = 0;
Delay_ms(500); }
else if (!GPIO.GP0 && GPIO.GP1) {
GPIO.GP4 = 0;
GPIO.GP5 = 1; }
else if (GPIO.GP0 && GPIO.GP1) {
GPIO.GP4 = 0;
GPIO.GP5 = 0;
Q = 1; }
else if ((!GPIO.GP0 && !GPIO.GP1) || (GPIO.GP0 && !GPIO.GP1 && !Q)) {
GPIO.GP4 = 1;
GPIO.GP5 = 0;
Q = 0; }
}
// return ();
}
Ср май 11, 2022 17:24:45
CMCON = 0b00000111;
Пн дек 12, 2022 13:49:28
Пн дек 12, 2022 17:45:21
Пн дек 12, 2022 18:17:13
Пн дек 12, 2022 18:59:07
Вт дек 13, 2022 06:27:06
Чт дек 15, 2022 10:45:36
void main()
{
...
INTCON=0b11001000;
// инициализация таймеров (0 и 2)
...
}
void interrupt isr(void)
{
if(RBIF) {
if(RB7==1) // вход сигнала на B7 (например)
//запуск таймера
if(RB7==0)
// остановка таймера, запись значения счётчика в регистр таймера ШИМ (не напрямую конечно, а после вычислений, учёта "мёртвых зон" и т.д.), сброс таймера
}
RBIF=0; // сброс флага прерывания
}
Чт дек 15, 2022 11:01:01
Чт дек 15, 2022 11:06:30
Чт дек 15, 2022 11:23:25
Чт дек 15, 2022 11:29:51
Чт дек 15, 2022 11:53:12
Чт дек 15, 2022 13:25:36
spongebob писал(а):я спросил что в какие регистры писать.
Вс июн 11, 2023 17:50:59
Пн июл 24, 2023 21:56:41
/*
* File: Clock_IN14_test
* Author: SolderCat
* v.1.01
* Created on 24 Jule 2023, 22:45
* MCU PIC16F628A
*/
#include "main.h"
//----------
unsigned char secs=0;
char hour=12, min=30;
unsigned char a[4];
volatile unsigned char bt;
unsigned char pwm_val;
//----------
#define OK (bt==1) //(buttons==1)
#define PLUS (bt==2) //(buttons==2)
#define MINUS (bt==3) //(buttons==3)
#define CLOCKMODE0 0
#define CLOCKMODEHOUR 1
#define CLOCKMODEMIN 2
#define CLOCKMODESEC 3
#define CLOCKMODEPWM 4
//----------
unsigned char button1state=0;
unsigned char clockmode=CLOCKMODE0;
//----------
void interrupt isr(void){
if(T0IF){
TIM0_Callback();
T0IF=0;
}
if(TMR1IF){
// TMR1L=0x00;
TMR1H=0x80;
TMR1IF=0;
secs++;
if (secs >= 60){
min++;
secs=0;
}
if (min >= 60){
min =0;
hour++;
}
if (hour >= 24){
hour =0;
}
}
}
//----------
void main(void){
PCONbits.OSCF = 1; // set Internal 4MHz
TRISB = 0x00;
PORTB = 0x00;
PORTA = 0x00;
TRISA = 0b00100010; // RA1 & RA5 to input
OPTION_REG=0b00000011; //Prescaler_16 4astota dynamiki
CMCON = 0x07;
T1CKPS0=0; //Prescaler 1 (32768/(corr)/1 = 1Hz)
T1CKPS1=0;
T1OSCEN=1; // enable clock
T1CONbits.nT1SYNC=1; //asynchron mode
TMR1CS=1; //External clock
TMR1L=0x00;
TMR1H=0x80;
T0IE=1;
PR2=0x3A;
pwm_val=eeprom_read(0x00);
__delay_ms(100);
CCP1CON=0x2F; //set 20 lvl
CCPR1L = 0x31; //set 20 lvl
T2CKPS1 = 0; //TIMER2 prescaler 1:1
T2CKPS0 = 0;
GIE=1;
PEIE=1;
TMR1IE=1;
TMR1ON=1;
TMR2ON=1; //TIMER2 ON
TMR0=0;
while(1){
//----------
if(OK){
if (clockmode==CLOCKMODE0)
{
clockmode=CLOCKMODEHOUR;
button1state=1;
bt=0;
}
}
//--Установка Часов------
if(clockmode==CLOCKMODEHOUR){
if(PLUS) {hour++;bt=0;}
if(MINUS) {hour--;bt=0;} //здесь не переходит с 0 на 23
if(hour>23) {hour=0;}
if(hour<0) {hour=23;}
RB2 = 1; //dot vklu4en
a[0]=0;
a[1]=0;
a[2]=hour%10;
a[3]=hour/10;
if(OK){
if(button1state==0)
{
clockmode=CLOCKMODEMIN;
button1state=1;
bt=0;
}
}
if (clockmode==CLOCKMODEHOUR) button1state=0;
}
//--Установка Минут-----------
if(clockmode==CLOCKMODEMIN){
if(PLUS) {min++;bt=0;}
if(MINUS) {min--;bt=0;} //здесь не переходит с 0 на 59
if(min>59) {min=0;}
if(min<0) {min=59;}
RB2 = 1;
a[0]=min%10;
a[1]=min/10;
a[2]=0;
a[3]=0;
if(OK){
if(button1state==0)
{
clockmode=CLOCKMODESEC;
button1state=1;
bt=0;
}
}
if (clockmode==CLOCKMODEMIN) button1state=0;
}
//--Уст Sec---------
if(clockmode==CLOCKMODESEC)
{
if(PLUS) {secs=0;}
if(MINUS) {secs=30;}
RB2 = 1;
a[0]=secs%10;
a[1]=secs/10;
a[2] = 0;
a[3] = 1;
if(OK){
if(button1state==0)
{
clockmode=CLOCKMODEPWM;
button1state=1;
bt=0;
}
}
if (clockmode==CLOCKMODESEC) button1state=0;
}
//--Уст PWM------
if(clockmode==CLOCKMODEPWM){
if(PLUS) {pwm_val=pwm_val+10;}
if(MINUS) {pwm_val=pwm_val-10;}
if(pwm_val<100) {pwm_val=230;}
else if(pwm_val>230) {pwm_val=100;}
CCPR1L = pwm_val>>2;
CCP1CON |= 0x30&(pwm_val<<4);
RB2 = 1;
a[0]=pwm_val/10%10;
a[1]=pwm_val/100%10;
a[2]=0;
a[3]=2;
eeprom_write(0x00,pwm_val);
if(OK){
if(button1state==0)
{
clockmode=CLOCKMODE0;
button1state=1;
bt=0;
}
}
if (clockmode==CLOCKMODEPWM) button1state=0;
}
//---Time------
if(clockmode==CLOCKMODE0){
if(secs&1)
{
RB2 = 0;
}
else
{
RB2 = 1;
}
a[0]=min%10;
a[1]=min/10%10;
a[2]=hour%10;
a[3]=hour/10%10;
}
//----------
}
}
}
Пн июл 24, 2023 22:05:07
Вт июл 25, 2023 20:01:56
Чт авг 17, 2023 16:30:53
Чт авг 17, 2023 21:39:31