#pragma config FOSC = INTOSCIO
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config MCLRE = ON
#pragma config CP = OFF
#pragma config IOSCFS = 4MHZ
#pragma config BOREN = ON
#define _XTAL_FREQ 4000000
#include <xc.h>
#define SHCP_on GPIObits.GP4=1 //3 GP4
#define SHCP_off GPIObits.GP4=0
#define DS_on GPIObits.GP1=1 //2 GP5
#define DS_off GPIObits.GP1=0
#define STCP_on GPIObits.GP5=1 //6 GP1
#define STCP_off GPIObits.GP5=0
void zdvig(char z);
char t=0b00000000;
char w=0b00000001;
char y=0b00000000;
char fButton=0;
char step = 0;
void main(void) {
TRISIO = 0b001101;//GP4 GP5 GP1 — output GP0-ADC
ANSEL = 0b000001;
ADCON0 = 0b10000000;
while(1){
unsigned int x;
ADON = 1; //ADC ON
__delay_ms(15); //
GO = 1; //start ADC
while(GO);
x = (ADRESH<<8) + ADRESL;
ADON = 0; // ADC off
if (x >857 ){//4.38
y=0b11110000;
}else if(x>819){//4.0
y=0b11100000;
}else if(x>778){//3.8
y=0b11000000;
}else{
y=0b10000000;
}
if(GPIObits.GP2 != 1){// knopka nazata
fButton = 1;
_delay(100);
}
if((GPIObits.GP2 != 0)&&(fButton==1)){
if(step<3) step++;
else step = 0;
fButton = 0;
_delay(100);
}
switch (step){
case 0:
zdvig((0b00000000|y));
break;
case 1:
zdvig((0b00001000|y));
break;
case 2:
zdvig((0b00001100|y));
break;
case 3:
zdvig((0b00001110|y));
break;
}
}
return;
}
void zdvig(char z) {
STCP_off;
for(char i=0;i!=8;i++){
t=w&z;
if(t==0b00000001){DS_on;__delay_ms(2);SHCP_on;__delay_ms(2); SHCP_off;__delay_ms(2);}
else {DS_off;__delay_ms(2);SHCP_on;__delay_ms(2); SHCP_off;__delay_ms(2);}
z=z>>1;
}
STCP_on;
}
СОДЕРЖАНИЕ
СОДЕРЖАНИЕ