#include <16f628.h>
#fuses XT,NOWDT
#use delay(clock=4000000)
#use fast_io(b)
#use fast_io(a)
#define arttir pin_b0
#define azalt pin_b1
int birler=0,sayi=0;
const int hane[10]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
unsigned int8 duty_oran=0;
unsigned int8 hassasiyet=25;
Void buton_kontrol(){
set_pwm1_duty(duty_oran);
if(duty_oran>=240)
duty_oran=0;
set_pwm1_duty(duty_oran);
}
void ayarla()
{
set_tris_b(0x03);
set_tris_a(0xc0);
}
void haneBul()
{
birler=sayi%10;
}
void displayYaz()
{
output_a(hane[birler]|(0b11100000));
delay_ms(2);
}
void main()
{
// setup_adc(ADC_CLOCK_DIV_2);
// setup_psp(PSP_DISABLED);
// setup_spi(SPI_SS_DISABLED);
//setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_vref(FALSE);
set_tris_b(0b00000011);
set_tris_a(0b11110000);
output_b(0x00);
//output_a(0x00);
ayarla();
setup_timer_2(T2_DIV_BY_16,254,1);
setup_CCP1(CCP_PWM);
set_pwm1_duty(duty_oran);
while(TRUE)
{
haneBul();
buton_kontrol();
displayYaz();
if(input(arttir))
{
delay_ms(5);
sayi++;
if(sayi==10) sayi=0;
delay_ms(1);
if(duty_oran<250)
duty_oran+=hassasiyet;
if(duty_oran >= 240)
duty_oran=0;
while(input(arttir))
{ displayYaz();
}
}
if(input(azalt)&&sayi!=0)
{
delay_ms(5);
sayi--;
haneBul();
delay_ms(1);
if(duty_oran>0)
duty_oran-=hassasiyet;
while(input(azalt)){displayYaz();
}
}
}
}