Simple LCD calculator with pic 16f84Овде е прикажан сорс програм за 16F84 или 16F628 за калкулатор.
#include <flex lcd.c>
#include <16F628A.h> //O 16F84A, es lo mismo..
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES MCLR
#use delay(clock=4000000)
int i=0, h=1, aux=0, m=100, mindex=0, findex=3;
int multi[4]={100,10,1};
char funcion[4]={'+','-','*','/'};
int sta=1;
long a=0, num1=0;
#int_timer0
void intb(void)
{
i++;
if (i==15)
{
h = 1;
disable_interrupts(GLOBAL);
}
}
void reset(void)
{
a = 0;
num1 = 0;
sta = 1;
mindex = 0;
m = 100;
}
void main()
{
set_tris_a(0b11111);
setup_counters (RTCC_INTERNAL, RTCC_DIV_64);
enable_interrupts(int_timer0);
lcd_init();
lcd_setcursor_vb(0, 1);
printf(lcd_putc,"\f%03.0Ld", a);
lcd_gotoxy(1,1);
while (TRUE)
{
if (input(PIN_A0) && h)
{
lcd_setcursor_vb(0, 1);
a = a + m;
lcd_gotoxy(sta, 1);
printf(lcd_putc,"%03.0Ld", a);
lcd_gotoxy(mindex+sta, 1);
aux = 1;
h = 0;
i = 0;
set_rtcc(0);
enable_interrupts(GLOBAL);
}
if (input(PIN_A1) && h)
{
if (++mindex == 3) mindex = 0;
m = multi[mindex];
lcd_gotoxy(mindex+sta, 1);
h = 0;
i = 0;
set_rtcc(0);
enable_interrupts(GLOBAL);
}
if (input(PIN_A2) && h)
{
if (aux) {
num1 = a;
a = 0;
sta = 5;
mindex = 2;
m = 1;
} aux=0;
if (++findex == 4) findex = 0;
lcd_gotoxy(4, 1);
printf(lcd_putc,"%c%03.0Ld",funcion[findex], a);
lcd_gotoxy(4, 1);
h = 0;
i = 0;
set_rtcc(0);
enable_interrupts(GLOBAL);
}
if (input(PIN_A3) && h)
{
switch (findex)
{
case 0: a = a + num1;
break;
case 1: a = num1 - a;
break;
case 2: a = a * num1;
break;
case 3: a = num1 / a;
break;
default: printf(lcd_putc,"\fError");
delay_ms(500);
reset_cpu();
break;
}
lcd_gotoxy(8, 1);
printf(lcd_putc,"=%Ld", a);
lcd_setcursor_vb(0, 0);
reset();
h = 0;
i = 0;
set_rtcc(0);
enable_interrupts(GLOBAL);
}
if (input(PIN_A4)&& h)
{
reset();
lcd_setcursor_vb(0, 1);
printf(lcd_putc,"\f%03.0Ld", a);
lcd_gotoxy(1,1);
h = 0;
i = 0;
set_rtcc(0);
enable_interrupts(GLOBAL);
}
}
}
Треба да се најде шемата и да ја ставам во темата