Схемка из основного сайта.
/*
* File: newmain.c
* Author: User
*
* Created on 19 ?????? 2024 ?., 14:20
*/
#include <htc.h>
#pragma config WDTE=OFF, MCLRE=OFF, BOREN=OFF, FOSC=INTRCIO, CP=OFF, CPD=OFF //,INTRCIO
#define _XTAL_FREQ 4000000
void main(void){
unsigned int count;
// PIC I/O init
CMCON = 0b111; //comparator off
GPIO = 0b00110110;
TRISIO = 0b00000001; //GPIO2 input
ANSEL = 0b01010001; //Fosc/16, AN0 pin7
ADCON0 = 0b10000001; //right justified, AN0, ADC on
while(1) {
GO_DONE = 1; //start ADC
while(GO_DONE){};
count=((ADRESH << 8) + ADRESL);
if(count>=1016){GPIO = 0b00100000;
__delay_ms(500);
GPIO = 0b00000000;}
if((count<1016)&&(count>=952)){GPIO = 0b00100000;}
if((count<952)&&(count>=918)){GPIO = 0b00010000;}
if((count<918)&&(count>=846)){GPIO = 0b00000100;}
if((count<846)&&(count>=776)){GPIO = 0b00000010;}
if((count<776)&&(count>600)){
GPIO = 0b00000010;
__delay_ms(500);
GPIO = 0b00000000;
}
if(count<600){
GPIO = 0b00110110;
__delay_ms(500);
GPIO = 0b00000000;
}
__delay_ms(500);
}
}
Файлы проекта.
Данный контент доступен только зарегистрированным пользователям.