/Designs/CT01B/SW/1_00/16F88.H
0,0 → 1,277
//////// Header file for the PIC16F88
#device PIC16F88
#nolist
//////// Program memory: 4096x14 Data RAM: 368 Stack: 8
//////// I/O: 16 Analog Pins: 7
//////// Data EEPROM: 256
//////// C Scratch area: 77 ID Location: 2000
// Fuses:
// Oscilator: LP - oscilator LP
// XT - oscilator XT
// HS - oscilator HS
// EC_IO - externi vstup, RA6/CLKO je IO port
// INTRC - RC oscilator, RA6/CLKO je CLKO, RA7/CLKI je IO port port,
// INTRC_IO - RC oscilator, RA6 i RA7 je IO port
// RC - ext RC, RA6/CLKO je CLKO
// RC_IO - ext RC, RA6 je IO port
// Watch: NOWDT - neni watchog
// WDT - je watchdog
// PUT: NOPUT - neni power up timer
// PUT - je power up timer
// MCLR: MCLR - RA5/MCLR je MCLR
// NOMCLR - RA5/MCLR je IO port
// BOR: BROWNOUT - BOR povolen
// NOBROWNOUT - BOR zakazan
// LVP: LVP - RB3/PGM je PGM
// NOLVP - RB3/PGM je IO port
// CPD: CPD - je ochrana EEPROM
// NOCPD - neni ochrana EEPROM
// WRT WRT - zakaz zapisu do pameti programu
// NOWRT - povolen zapis do pameti programu
// DEBUG: DEBUG - RB6 a RB7 jsou ICD port
// NODEBUG - RB6 a RB7 jsou IO port
// CCPMX: CCPB0 - CCP/PWM na RB0
// CCPB3 - CCP/PWM na RB3
// CP: PROTECT - pamet programu je chranena
// NOPROTECT - pamet programu neni chranena
//
 
////////////////////////////////////////////////////////////////// I/O
// Discrete I/O Functions: SET_TRIS_x(), OUTPUT_x(), INPUT_x(),
// PORT_B_PULLUPS(), INPUT(),
// OUTPUT_LOW(), OUTPUT_HIGH(),
// OUTPUT_FLOAT(), OUTPUT_BIT()
// Constants used to identify pins in the above are:
 
 
 
#define PIN_A0 40
#define PIN_A1 41
#define PIN_A2 42
#define PIN_A3 43
#define PIN_A4 44
#define PIN_A5 45
#define PIN_A6 46
#define PIN_A7 47
 
#define PIN_B0 48
#define PIN_B1 49
#define PIN_B2 50
#define PIN_B3 51
#define PIN_B4 52
#define PIN_B5 53
#define PIN_B6 54
#define PIN_B7 55
 
////////////////////////////////////////////////////////////////// Useful defines
#define FALSE 0
#define TRUE 1
 
#define BYTE int
#define BOOLEAN short int
 
#define getc getch
#define fgetc getch
#define getchar getch
#define putc putchar
#define fputc putchar
#define fgets gets
#define fputs puts
 
////////////////////////////////////////////////////////////////// Control
// Control Functions: RESET_CPU(), SLEEP(), RESTART_CAUSE()
// Constants returned from RESTART_CAUSE() are:
#define WDT_FROM_SLEEP 0
#define WDT_TIMEOUT 8
#define MCLR_FROM_SLEEP 16
#define NORMAL_POWER_UP 24
 
 
////////////////////////////////////////////////////////////////// Timer 0
// Timer 0 (AKA RTCC)Functions: SETUP_COUNTERS() or SETUP_TIMER0(),
// SET_TIMER0() or SET_RTCC(),
// GET_TIMER0() or GET_RTCC()
// Constants used for SETUP_TIMER0() are:
#define RTCC_INTERNAL 0
#define RTCC_EXT_L_TO_H 32
#define RTCC_EXT_H_TO_L 48
 
#define RTCC_DIV_1 8
#define RTCC_DIV_2 0
#define RTCC_DIV_4 1
#define RTCC_DIV_8 2
#define RTCC_DIV_16 3
#define RTCC_DIV_32 4
#define RTCC_DIV_64 5
#define RTCC_DIV_128 6
#define RTCC_DIV_256 7
 
 
#define RTCC_8_BIT 0
 
// Constants used for SETUP_COUNTERS() are the above
// constants for the 1st param and the following for
// the 2nd param:
 
////////////////////////////////////////////////////////////////// WDT
// Watch Dog Timer Functions: SETUP_WDT() or SETUP_COUNTERS() (see above)
// RESTART_WDT()
//
#define WDT_18MS 8
#define WDT_36MS 9
#define WDT_72MS 10
#define WDT_144MS 11
#define WDT_288MS 12
#define WDT_576MS 13
#define WDT_1152MS 14
#define WDT_2304MS 15
 
////////////////////////////////////////////////////////////////// Timer 1
// Timer 1 Functions: SETUP_TIMER_1, GET_TIMER1, SET_TIMER1
// Constants used for SETUP_TIMER_1() are:
// (or (via |) together constants from each group)
#define T1_DISABLED 0
#define T1_INTERNAL 0x85
#define T1_EXTERNAL 0x87
#define T1_EXTERNAL_SYNC 0x83
 
#define T1_CLK_OUT 8
 
#define T1_DIV_BY_1 0
#define T1_DIV_BY_2 0x10
#define T1_DIV_BY_4 0x20
#define T1_DIV_BY_8 0x30
 
////////////////////////////////////////////////////////////////// Timer 2
// Timer 2 Functions: SETUP_TIMER_2, GET_TIMER2, SET_TIMER2
// Constants used for SETUP_TIMER_2() are:
#define T2_DISABLED 0
#define T2_DIV_BY_1 4
#define T2_DIV_BY_4 5
#define T2_DIV_BY_16 6
 
////////////////////////////////////////////////////////////////// CCP
// CCP Functions: SETUP_CCPx, SET_PWMx_DUTY
// CCP Variables: CCP_x, CCP_x_LOW, CCP_x_HIGH
// Constants used for SETUP_CCPx() are:
#define CCP_OFF 0
#define CCP_CAPTURE_FE 4
#define CCP_CAPTURE_RE 5
#define CCP_CAPTURE_DIV_4 6
#define CCP_CAPTURE_DIV_16 7
#define CCP_COMPARE_SET_ON_MATCH 8
#define CCP_COMPARE_CLR_ON_MATCH 9
#define CCP_COMPARE_INT 0xA
#define CCP_COMPARE_RESET_TIMER 0xB
#define CCP_PWM 0xC
#define CCP_PWM_PLUS_1 0x1c
#define CCP_PWM_PLUS_2 0x2c
#define CCP_PWM_PLUS_3 0x3c
long CCP_1;
#byte CCP_1 = 0x15
#byte CCP_1_LOW= 0x15
#byte CCP_1_HIGH= 0x16
////////////////////////////////////////////////////////////////// COMP
// Comparator Variables: C1OUT, C2OUT
// Constants used in setup_comparators() are:
#define A0_A3_A1_A2 4
#define A0_A2_A1_A2 3
#define NC_NC_A1_A2 5
#define NC_NC_NC_NC 7
#define A0_VR_A1_VR 2
#define A3_VR_A2_VR 10
#define A0_A2_A1_A2_OUT_ON_A3_A4 6
#define A3_A2_A1_A2 9
 
#bit C1OUT = 0x1f.6
#bit C2OUT = 0x1f.7
 
////////////////////////////////////////////////////////////////// VREF
// Constants used in setup_vref() are:
#define VREF_LOW 0xa0
#define VREF_HIGH 0x80
#define VREF_A2 0x40
 
////////////////////////////////////////////////////////////////// INT
// Interrupt Functions: ENABLE_INTERRUPTS(), DISABLE_INTERRUPTS(),
// EXT_INT_EDGE()
//
// Constants used in EXT_INT_EDGE() are:
#define L_TO_H 0x40
#define H_TO_L 0
// Constants used in ENABLE/DISABLE_INTERRUPTS() are:
#define GLOBAL 0x0BC0
#define INT_RTCC 0x0B20
#define INT_RB 0x0B08
#define INT_EXT 0x0B10
#define INT_TBE 0x8C10
#define INT_RDA 0x8C20
#define INT_TIMER1 0x8C01
#define INT_TIMER2 0x8C02
#define INT_CCP1 0x8C04
#define INT_SSP 0x8C08
#define INT_COMP 0x8D40
#define INT_EEPROM 0x8D10
#define INT_TIMER0 0x0B20
 
// Definice reistru pro pristup k EEPROM
#define EEDATA 0x010C
#define EEADR 0x010D
#define EEDATAH 0x010E
#define EEADRH 0x010F
#define EECON1 0x018C
#define EECON1_RD 0
#define EECON1_WR 1
#define EECON1_WREN 2
#define EECON1_WRERR 3
#define EECON1_FREE 4
#define EECON1_EEPGD 7
#define EECON2 0x018D
#define PIR2 0x000D
#define PIR2_EEIF 4
#define PIE2 0x008D
#define PIR2_EEIE 4
 
// Definice pro AD prevodnik
#define ADCON0 0x1F
#define ADCON1 0x9F
#define ADRESH 0x1E
#define ADRESL 0x9E
#define ANSEL 0x9B
 
// Definice pro casovac a PWM
#define PR2 0x92
#define T2CON 0x12
#define CCP1CON 0x17
#define CCPR1L 0x15
 
// Definice pro komparator
#define CMCON 0x9C
 
// Definice pro preruseni
#define INTCON 0x0B
#bit GIE = INTCON.7
#bit PEIE = INTCON.6
#bit TMR0IE = INTCON.5
#bit INTE = INTCON.4
#bit RBIE = INTCON.3
#bit TMR0IF = INTCON.2
#bit INTF = INTCON.1
#bit RBIF = INTCON.0
 
#define PIE1 0x8C
#bit ADIE = PIE1.6
#bit RCIE = PIE1.5
#bit TXIE = PIE1.4
#bit SSPIE = PIE1.3
#bit CCP1IE = PIE1.2
#bit TMR2IE = PIE1.1
#bit TMR1IE = PIE1.0
 
// Porty
#define PORTA 0x05
#define PORTB 0x06
#define TRISA 0x85
#define TRISB 0x86
 
#list
/Designs/CT01B/SW/1_00/A.BAT
0,0 → 1,4
call picpgr stop
call picpgr erase pic16f88
call picpgr program CT01A100.hex hex pic16f88
call picpgr run
/Designs/CT01B/SW/1_00/CT01A100.C
0,0 → 1,368
// Firmware pro pripravek pro testovani slunecnich clanku CT01A
// (c) miho 2005
//
// 1.00 Zakladni verze
 
#include <16F88.h>
#fuses INTRC_IO, NOWDT, NOPUT, NOPROTECT, NOBROWNOUT, MCLR, NOLVP, NOCPD, NODEBUG, CCPB3
 
#use delay(clock=8000000) // interni RC oscilator
 
#use RS232 (baud=9600, xmit=PIN_B5, rcv=PIN_B2)
 
#include <eeprom.c> // Podpora zapisu promennych do EEPROM
 
#define LCD_E PIN_A2
#define LCD_RS PIN_A7
#define LCD_D0 PIN_A3
#define LCD_D1 PIN_A4
#define LCD_D2 PIN_B7
#define LCD_D3 PIN_B6
 
#include <LCD.C> // podpora LCD displeje
 
 
// Globalni nastaveni a globalni promenne
//
#define Ofset 5 // ofset PWM pro nulovy proud
float Vref; // konstanta voltmetru (napeti 1 LSB prevodniku)
int1 Xrs; // 1 znamena vystup na RS232
int1 Xlcd; // 1 znamena vystup na LCD displej
 
 
signed int16 Convert(int8 Chanel)
// Prevod AD prevodnikem ze zadaneho kanalu
// Vysledek je na 10 bitu, doba prevodu 1.8ms
{
unsigned int16 Data;
int i;
 
// AD prevod s prumerovanim 32x
Data=0;
*ADCON0 = 0x41 | Chanel << 3; // frekvence f/16, zapnout, cislo kanalu
*ADCON1 = 0xC0; // right justify, Vdd a Vss jako reference
delay_us(100); // ustaleni vstupu
for(i=32;i!=0;i--)
{
*ADCON0 |= 4; // start prevodu
delay_us(50); // prevod
Data += (int16)*ADRESH<<8|*ADRESL; // vysledek se nascita
}
Data=Data>>5; // odcin prumerovani
 
// Vysledek
return Data; // vysledek 0 az 1023
}
 
 
float GetVoltage()
// Provede nacteni dat z AD prevodniku a prevod na float napeti
{
float Data;
Data=(Convert(0)-Convert(1))*Vref;
return Data;
}
 
 
void SetPWM(int8 Data)
// Nastaveni dat do PWM vystupu
// Celych 8 bitu, doba behu 10ms
{
*CCPR1L = Data>>2; // hornich 6 bitu
*CCP1CON = *CCP1CON & 0x0F | (Data & 3)<<4; // spodni 2 bity
delay_ms(50); // doba na ustaleni
}
 
 
void GetString(char *s, int max)
// Nacte ze seriovky retezec,
// dela echo a hlida delku retezce
{
int len; // aktualni delka
char c; // nacteny znak
 
max--;
len=0;
do {
c=getc();
if(c==8) { // Backspace
if(len>0) {
len--;
putc(c);
putc(' ');
putc(c);
}
} else if ((c>=' ')&&(c<='~'))
if(len<max) {
s[len++]=c;
putc(c);
}
} while(c!=13);
s[len]=0;
}
 
 
float atof(char *s)
// Prevod retezce na float
{
float pow10 = 1.0;
float result = 0.0;
int sign = 0;
char c;
int ptr = 0;
 
c = s[ptr++];
 
if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') {
if(c == '-') {
sign = 1;
c = s[ptr++];
}
if(c == '+')
c = s[ptr++];
 
while((c >= '0' && c <= '9')) {
result = 10*result + c - '0';
c = s[ptr++];
}
 
if (c == '.') {
c = s[ptr++];
while((c >= '0' && c <= '9')) {
pow10 = pow10*10;
result += (c - '0')/pow10;
c = s[ptr++];
}
}
 
}
 
if (sign == 1)
result = -result;
return(result);
}
 
 
signed int atoi(char *s)
// Preved retezec na int (jen dekadicka cisla)
{
signed int result;
int sign, index;
char c;
 
index = 0;
sign = 0;
result = 0;
 
// Omit all preceeding alpha characters
if(s)
c = s[index++];
 
// increase index if either positive or negative sign is detected
if (c == '-')
{
sign = 1; // Set the sign to negative
c = s[index++];
}
else if (c == '+')
{
c = s[index++];
}
 
while (c >= '0' && c <= '9')
{
result = 10*result + (c - '0');
c = s[index++];
}
 
if (sign == 1)
result = -result;
 
return(result);
}
 
 
void Xputc(char c)
// Spolecna procedura pro vystup znaku na LCD a RS232
// dle stavu promennych Xrs a Xlcd
{
if (Xrs)
if(c!='\n') putc(c); // vystup na RS232 (neposilej LF)
if (Xlcd) lcd_putc(c); // vystup na LCD displej
}
 
 
void Calibrate()
// Procedura pro kalibraci
{
#define LINE_LEN 40 // delka retezce
char Line[LINE_LEN]; // retezec
int8 Data; // nacteny proud 0 az 250
float FData; // nactene rozdilove napeti
 
lcd_clr();
printf(Xputc,"\n\rCalibration\r\n");
for(;1;)
{
Xrs=1;
Xlcd=1;
GetString(Line,LINE_LEN);
if (*Line=='q')
{
// Ukonceni procesu kalibrace
SetPWM(0); // vypni proud
printf("\n\r"); // odradkuj na terminalu
EE_WR(0,Vref); // uloz kalibraci do EEPROM
return; // navrat
}
else if (*Line=='v')
{
// Zadani nove hodnoty Vref
Vref=atof(Line+1)/1023; // referencni napeti na 1 LSB
printf("\r\n");
}
else if(*Line)
{
// Zadan novy proud
Data=atoi(Line); // preved retezec na cislo
printf(Xputc," Set %3umA\r\n",Data);
SetPWM(Data+Ofset); // nastav proud
delay_ms(100); // cas na ustaleni
}
// Jeden cyklus mereni
FData=GetVoltage();
printf(Xputc,"%1.2fV \r\n",FData);
}
lcd_clr(); // smaz displej
}
 
 
void AutoRun()
// AutoRun - automaticke mereni cele zatezovaci krivky
{
float FData; // zmerene napeti
int8 i; // promenna cyklu - proud v mA
 
Xrs=0; // vystup neni na RS232
Xlcd=1; // vystup je na LCD
printf(Xputc,"\fAutoRun"); // napis na LCD
Xrs=1; // hlavika jen na RS232
Xlcd=0;
printf(Xputc,"\r\nI[mA] U[V] P[mW]");
Xlcd=1;
 
SetPWM(0); // vypni proud
delay_ms(100); // klidova podminka
for(i=0;i<=250;i++) // cyklus pres proud 0 az 250mA
{
SetPWM(i+Ofset); // nastav proud
FData=GetVoltage(); // zmer napeti
if (FData>0) printf(Xputc,"\r\n%03u %1.2f %3.1f",i,FData,FData*i);
else i=250; // predcasne ukonceni
}
printf(Xputc,"\r\n"); // na konci odradkuj
SetPWM(0); // vypni proud
lcd_clr(); // smaz displej
}
 
 
void main()
{
// Hodiny
*0x8F = 0x72; // 8 MHz interni RC oscilator
 
// Digitalni vystupy
output_low(PIN_B0); // nepouzity
output_low(PIN_B1); // nepouzity
output_low(PIN_B3); // PWM vystup
output_high(PIN_B5); // TX data
port_b_pullups(TRUE); // vstupy s pull up odporem
 
// Analogove vstupy
*ANSEL = 0x03; // AN0 a AN1
 
// Inicializace LCD
lcd_init();
Xrs=1;
Xlcd=1;
printf(Xputc,"\fSolar Cell\r\nTester 1.00\r");
 
// Inicializace PWM 8 bitu
*PR2 = 0x3F; // perioda PWM casovace
*T2CON = 0x04; // povoleni casovace T2 bez preddelicu a postdelicu
*CCP1CON = 0x0C; // PWM mode, lsb bity nulove
*CCPR1L = 0; // na zacatku nulova data
output_low (PIN_B3); // PWM vystup
 
// Kalibrace pri drzenem tlacitku
EE_RD(0,Vref); // vytahni kalibracni konstantu z EEPROM
if (input(PIN_B4)==0) // otestuj tlacitko
{
delay_ms(200);
Calibrate(); // pokud je stalceno spust kalibraci
}
else
{
delay_ms(1000); // jinak jen 1s spozdeni
}
lcd_clr(); // smaz displej
 
// Hlavni smycka
{
int8 il,ih,im; // spodni a horni mez a maximum proudu
int8 i; // promenna cyklu
float Voltage,Power; // zmerene rozdilova napeti a vypocteny vykon
float MaxVoltage,MaxPower; // maximalni hodnoty
 
// Cihej na stisk tlacitka
0==PORTB; // jen precti port B
RBIF=0; // nuluj priznak preruseni od zmeny
 
// Pocatecni meze
il=0;
ih=10;
 
// Trvale prohledavani
for(;1;)
{
 
if (RBIF) // kdyz je tlacitko
{
AutoRun();
while (~input(PIN_B4)); // cti port B a cekej na uvolneni
RBIF=0;
}
 
Xrs=0;
Xlcd=1;
printf(Xputc,"\rOpt. [mA V mW]"); // napis na LCD
 
MaxVoltage=0; // inicializace maxim
MaxPower=0;
im=0;
 
for(i=il;i<=ih;i++) // dilci cyklus hledani
{
SetPWM(i+Ofset); // nastav proud
Voltage=GetVoltage(); // precti rozdilove napeti
Power=Voltage*i; // vypocti vykon
if (Power>MaxPower) // zkontroluj maximu
{
MaxVoltage=Voltage; // zapamatuj si maximum
MaxPower=Power;
im=i;
}
}
 
// Zobrazeni vysledku
Xrs=0;
Xlcd=1;
printf(Xputc,"\r\n%3u %1.2f %3.1f ", im, MaxVoltage, MaxPower);
 
// Natav nove meze
if (im>5) il=im-5; else il=0;
if (il>240) il=240;
ih=il+10;
}
}
}
/Designs/CT01B/SW/1_00/CT01A100.HEX
0,0 → 1,412
:1000000008308A00BC2B00000A108A100A118207EF
:1000100028340C34013406340A108A100A1182077D
:100020000A340D34433461346C34693462347234CC
:100030006134743469346F346E340D340A340034EE
:100040000A108A100A11820753346534743420343C
:100050002534333475346D3441340D340A3400346E
:100060000A108A100A118207253431342E343234B2
:100070006634563420340D340A3400340A108A10A1
:100080000A1182070C344134753474346F3452349D
:1000900075346E3400340A108A100A1182070D3448
:1000A0000A3449345B346D3441345D342034553482
:1000B0005B3456345D34203450345B346D34573403
:1000C0005D3400340A108A100A1182070C3453344C
:1000D0006F346C34613472342034433465346C349E
:1000E0006C340D340A3454346534733474346534E8
:1000F0007234203431342E34303430340D34003402
:100100000A108A100A1182070D344F347034743487
:100110002E3420345B346D34413420345634203452
:100120006D3457345D340034A33084000008031963
:10013000A6280230F800F701F70B9C28F80B9B2843
:100140009730F700F70BA228800B9928003483160C
:100150002918AE2883128511B028831683128515BD
:1001600083168511A918B82883120512BA28831698
:1001700083120516831605122919C22883128613C5
:10018000C42883168312861783168613A919CC28D0
:1001900083120613CE2883168312061783160613BE
:1001A0008312051583160511000000008312051146
:1001B00083160511831200348316A708031DE42853
:1001C00083128513E62883168312851783168513F9
:1001D000A80E2808A9008312A7208316A80E2808B5
:1001E000A9008312A7201A30F700F70BF5280000AA
:1001F000003414308316A3008312942085138316D1
:10020000851383120511831605118312B90139086C
:10021000023C031C172902308316A300831294208A
:1002200003308316A9008312A720B90A07291A30C0
:10023000F700F70B1929000002308316A90083127A
:10024000A7201A30F700F70B23290000B90139085D
:10025000023C031C3D2939080420BA008316A7017B
:1002600083123A088316A8008312DC20023083161A
:10027000A30083129420B90A27298A15E22B83163A
:100280008612831286120830F80000000000000079
:10029000F8175B29F8138316A20C8312031886162D
:1002A000031C861278175B297813F80B4B29000082
:1002B0000000000086163F308400840B5D29F81B87
:1002C0004A29781B54290034013083162302A500E3
:1002D0002408023C031D6E294030A50725088038FC
:1002E000A600A7012608A8008312DC20003483168C
:1002F0002208F7000C307702831203198C290A3088
:100300007702031998290D3077020319A0290830C4
:1003100077020319A729AE298316A7010130A80087
:100320008312DC2002308316A30083129420BC29A0
:1003300001308316A3000230A40083126421BC297B
:1003400001308316A300A40083126421BC29831604
:10035000A7011030A8008312DC20BC2983162208D4
:100360001F3C031CB5290730A2050130A700220855
:10037000A8008312DC20BC290034241CCA2983165F
:1003800021080A3C0319C9292108A20083123F2130
:1003900083168312A41CD12983162108A20083127C
:1003A000772100343A08BA0A84003908B90ABD0036
:1003B00003178D008F0183168C130C1483120C0805
:1003C00080000313BB0BD2298A15092C0C3083162D
:1003D000A2008312772100340830F7008316061537
:1003E00083120619F129EA01F717042AF713042AE0
:1003F000031006190314EA0C7717042A7713F70B76
:10040000F8296A08F8000F2A3F30F71B1130F8006E
:10041000F80B082AF71BF629771BFE29F8298A15FD
:100420001D28670C9500950C3F30950517080F396E
:10043000E80067080339F700F70EF030F705770892
:100440006804970032308316A3008312942000348E
:100450008316200803199A2AA800240803199A2A47
:10046000A807031C342A3B2A7F30A802031C9A2ABF
:1004700003199A2A3F2A8130A80703189A2A2808C4
:10048000F700F801F901FA012108AC00AC172208C5
:10049000AB002308AA001830A800A9012A1C682A6A
:1004A0002708FA07031C5A2AF90A031D5A2AF80AD0
:1004B0000319A9172608F907031C612AF80A03196A
:1004C000A9172508A200A2172208F8070318A917E0
:1004D000A90DF80CF90CFA0CAC0CAB0CAA0C03101F
:1004E000A80B4D2A0130F70703189A2AF81B7F2A18
:1004F000AC0DFA0DF90DF80DF70303199A2AAC1F8C
:10050000902AFA0A031D902AF90A031D902AF80A74
:10051000031D902AF80CF90CFA0CF70A03199A2A11
:100520002108A9002508A906A91F982AF8179E2ABC
:10053000F8139E2AF701F801F901FA01000083126D
:1005400000348E30F70083162508F8002408F900DF
:10055000FA01F808031DB62A7908F800F9010830F5
:10056000F702F808031DB62AF701BE2A0310F81B8C
:10057000BD2AF90DF80DF703B62AF813000083120F
:1005800000348030031CC72A8316AD0683128316FD
:10059000B2012908B1002D08B10628080319B22BB1
:1005A000B000F7002C080319BB2BB0020319582B1D
:1005B0000318DB2A172B2D08B600B6172E08B50036
:1005C0002F08B400B3010310B60CB50CB40CB30C77
:1005D000B00BE22AB11FEF2A3214CF2B32103010A9
:1005E0003216AB308400E52B3212B11B012B301CCC
:1005F0000C2BB60CB50CB40CB30CF70A0319CA2BB0
:100600000C2BB61B0F2B0310B30DB40DB50DB60D8F
:10061000F7030319CA2B012B3217772B3213290842
:10062000B100A91F152BB617C32BB613C32B2C086B
:10063000B000F7002808B0022908B600B6172A084B
:10064000B5002B08B400B3010310B60CB50CB40C04
:10065000B30CB00B232BB11F302BB214CF2BB21025
:100660003010B216AF308400E52BB212B11B422B12
:10067000301C4D2BB60CB50CB40CB30CF70A031997
:10068000CA2B4D2BB61B502B0310B30DB40DB50D5B
:10069000B60DF7030319CA2B422BB217772BB213EF
:1006A0002D08B100AD1F562BB617C32BB613C32BA5
:1006B0002D08B600B6172E08B5002F08B400B11FDC
:1006C000652BB6133215CF2B3211B3013010AB307E
:1006D0008400E52BB11B8D2B2908B100301C772B32
:1006E000B60CB50CB40CB30CF70A0319CA2BB31F24
:1006F000882BB40A031D882BB50A031D882BB60A64
:10070000031D882BB60CB50CB40CF70A0319CA2BC1
:10071000321B0E2BB21B4F2BAC2B8030B606B61FF4
:10072000952BCF2B2D08B100A22B2908B100B608BC
:10073000031DA22BB508031DA22BB408031DA22B79
:10074000F701C32BB61BAC2B0310B30DB40DB50DC5
:10075000B60DF70BA22BCA2BB11FB02BB617C32BAC
:10076000B613C32B2C08F7002D08B6002E08B500D1
:100770002F08B400C32B2808F7002908B6002A0860
:10078000B5002B08B4003608F8003508F900340825
:10079000FA00042CF701F801F901FA01042CB30165
:1007A000B409B509B609B309B30A031DDE2BB40AAF
:1007B000031DDE2BB50A031DDE2BB60A3218EE2A06
:1007C000B2182F2B3219642B922B0008B407031C8C
:1007D000EF2BB50A031DEF2BB60A0319301484035F
:1007E0000008B507031CF72BB60A0319301484035D
:1007F0000008801BFC2B803AB60703183014321A0D
:10080000F42AB21A352B6A2B0000831200348316A7
:1008100021080319CE2CAD0025080319CE2CAD02FA
:100820000318132C182C7F30AD070318CE2C1E2C68
:100830008130AD02031CCE2C0319CE2C2D08F700FD
:10084000F801F901FA01AC012208AB00AB1723084B
:10085000AA002408A9001930AD002808A90203182D
:10086000412C0130AA020318412CAB020318412C81
:10087000AC020318412CAC0AAB0AAA0A2808A90743
:10088000732C2708AA0203185C2C0130AB02031852
:100890005C2CAC0203185C2CAC0AAB0A2708AA0734
:1008A0002808A907031C732CAA0A031D732CAB0A82
:1008B000031D732CAC0A732C26088038AB02031876
:1008C000722C0130AC020318722CAC0A2608803856
:1008D000AB072708AA07031C502CAB0A031D502C9A
:1008E000AC0A502C7A14AD0B762C812C0310A90D78
:1008F000AA0DAB0DAC0D0310FA0DF90DF80DAE0DF0
:100900002D2C2E1C892C0310F80CF90CFA0CAE0CB3
:100910008C2CF7030319CE2CAE1BB52C0310A90D9C
:10092000AA0DAB0DAC0D2808A9020318A12C0130AB
:10093000AA020318A12CAB020318A12CAC02031CC1
:10094000C42C2708AA020318AC2C0130AB020318F0
:10095000AC2CAC02031CC42C26088038AB02031854
:10096000B52C0130AC02031CC42CFA0A031DC42CA4
:10097000F90A031DC42CF80A031DC42CF70A031935
:10098000CE2CF80CF90CFA0C2208AD002608AD06A6
:10099000AD1FCC2CF817D22CF813D22CF701F8018C
:1009A000F901FA010000831200346B086C068039EB
:1009B000ED00EB1FDD2CEB09EB0AEC1FE12CEC0941
:1009C000EC0AF701F8016B0803106C18F707F70C35
:1009D000F80CEC18F707F70CF80C6C19F707F70C84
:1009E000F80CEC19F707F70CF80C6C1AF707F70C72
:1009F000F80CEC1AF707F70CF80C6C1BF707F70C60
:100A0000F80CEC1BF707F70CF80CED1F092DF80993
:100A1000F80A8A155B2A6B08F8016A020318132D7D
:100A20006A08F7001F2DF7010830EC00EA0DF70DFA
:100A30006B0877020318F700F80DEC0B162D003445
:100A400078086808EA006430EB000B257708E800B6
:100A500078083030031D332D6918E915E9193B2D4D
:100A6000691A2030352DE9116912F80778088316C4
:100A7000A1008312BD216808EA000A30EB000B25B3
:100A80007708E80078083030031D4A2DE919502D09
:100A9000691A2030F80778088316A1008312BD2157
:100AA0003030E80768088316A1008312BD210034A6
:100AB000EE01ED016C0DF700F70DF70DF830F705BD
:100AC000770841389F00C03083169F004230F700FE
:100AD000F70B682D000020308312EF00EF08031998
:100AE000872D1F152130F700F70B742DF1011E081B
:100AF000F300F201720883161E04F70077088312D0
:100B0000ED070318EE0A7308EE07EF036E2DEE0CE7
:100B1000ED0CEE0CED0CEE0CED0CEE0CED0CEE0C09
:100B2000ED0C0730EE056D08F8006E08F900003492
:100B30008E30F7006F08F8006E08F900FA01EF1F19
:100B4000A72DF809F909F90A031DA72DF80AF808D5
:100B5000031DB42D7908F800F9010830F702F808F0
:100B6000031DB42DF701BE2D0310F81BBB2DF90D8D
:100B7000F80DF703B42DEF1BBE2DF81300008A11FA
:100B8000D82DEC0158257908EB007808EA000130EF
:100B9000EC00582578086A02EC006B08ED00790833
:100BA000031C790FED026D08EF006C08EE00982D24
:100BB0007A088316A3007908A2007808A1007708B4
:100BC000A000831223088316A7008312220883162D
:100BD000A600831221088316A5008312200883161D
:100BE000A400831228227A08E9007908E80078082E
:100BF000E7007708E6006608F7006708F80068086D
:100C0000F9006908FA0000340408EF00F001E71F5A
:100C10000E2E2D308316A1008312BD21E717660822
:100C20000319B22E7F306602031C6D2EE600F5011B
:100C30000430F6000310E90DE80DE70DF00DF60B9A
:100C40001A2E0430660203182D2E03306602031D8F
:100C5000A72E0A307002031CA72E0330E602F50A05
:100C600054270310E90DE80DE70DF00D3D27023084
:100C7000F6000310F00CE70CE80CE90CF60B392E2B
:100C800054270430F6000310F10CF20CF30CF40CB2
:100C9000F60B432E3D2754277308F4007208F30027
:100CA0007108F200F1013D2754277208F400710821
:100CB000F300F101F2013D27F019212EE608031D92
:100CC000662EE90AE80AE70AF00AA72E0310E90DE2
:100CD000E80DE70DF00DE603212EE609E60A7F3068
:100CE000E607F5010430F6000310E90DE80DE70D05
:100CF000F00DF60B742E0430E60705306602031C77
:100D0000B42E54270310E90DE80DE70DF00D031084
:100D1000E90DE80DE70DF00D3D270310E90DE80D95
:100D2000E70DF00DF50A0330F6000310F00CE70CA8
:100D3000E80CE90CF60B952E0330E602701E7D2EB2
:100D40000310F00CE70CE80CE90CE6037D2EE60935
:100D5000E60A0330E6077508EB007508ED006F0A38
:100D6000ED07E12E6F0AF50030308316A1008312E3
:100D7000BD21EF0803193B2F2E308316A1008312EB
:100D8000BD217508EE00EE036F086E02031CCA2E2B
:100D90006F08EE00EE080319D42E30308316A10040
:100DA0008312BD21EE0BCD2E7508F6006F0AF602F8
:100DB00003185D2FE6036F0AED007508ED026D085C
:100DC000EB007008EA0066080319EB2EEC00031034
:100DD000EA0CEC0BE72E6D0803193B2F30306A0745
:100DE0008316A1008312BD216B08031DFF2EEF089F
:100DF00003193B2F2E308316A1008312BD21EB0374
:100E0000ED0303193B2F660803190B2FEC000310A9
:100E1000EA0DEC0B072F6A08F0027008F100670872
:100E2000F2006808F3006908F4000310E90DE80D0A
:100E3000E70DF00D0310E90DE80DE70DF00D740856
:100E4000E907031C282FE80F282FE70F282FF00AA7
:100E50007308E807031C2F2FE70F2F2FF00A7208E3
:100E6000E7070318F00A7108F0070310E90DE80D11
:100E7000E70DF00DE12E00005D2F7408E907031C5B
:100E8000462FE80F462FE70F462FF00A7308E807B2
:100E9000031C4D2FE70F4D2FF00A7208E7070318C8
:100EA000F00A7108F00700347008F1006708F200DA
:100EB0006808F3006908F4000034000000343F08BB
:100EC000C6004308C606C61F6A2F03110310BF1BC6
:100ED00003149D2F3F08C6004208C7003E08C70202
:100EE0000319782FC61F9D2F0308013A83009D2FF9
:100EF0004308C7003F08C7020319842FC61F9D2F50
:100F00000308013A83009D2F4408C7004008C70228
:100F10000319902FC61F9D2F0308013A83009D2FB0
:100F20004508C7004108C70203199C2FC61F9D2F03
:0C0F30000308013A83009D2F03100034D9
:101000008A11E6218A15E60166088A110C208A15E4
:10101000E60A8316A1008A118312BD218A150F30BA
:101020006602031D04282414A4143930E600283075
:10103000E700E703E8018A11EC298A157808E9003E
:10104000083C031D3D28E80803193C28E80369080B
:101050008316A2008A1183123F218A15203083163D
:10106000A2008A1183123F218A1569088316A20003
:101070008A1183123F218A15562869081F3C0318DC
:10108000562869087E3C031C562867086802031826
:1010900056286808E80A660784006908800069081D
:1010A0008316A2008A1183123F218A1569080D3C1C
:1010B000031D1B28660868078400800139308400FE
:1010C0000008713C031DA528E7018A1111228A1529
:1010D0000A308316A2008A1183123F218A150D302F
:1010E0008316A2008A1183123F218A15E60120305F
:1010F000E7000430E8006608E60AE9006708E70A46
:1011000084000008EA00690803178D008F010313AB
:101110006A0803178C0083168C130C1583120313B3
:101120000B08F7008B138316031755308D00AA3078
:101130008D008C148C189A280C11770883120313D5
:101140008B04E80B7B28DD2AB02A393084000008A4
:10115000763C031D232A3A30E6007F30E700E801A1
:10116000E901EA01EB01EC01ED01EE01EF01F10112
:101170007108F10A660784000008F0002F3C03188C
:10118000C5287008393C0318D12870082B3C031976
:10119000D12870082D3C0319D12870082E3C031D5E
:1011A000DF2970082D3C031DDD280130EF00710898
:1011B000F10A660784000008F00070082B3C031D4C
:1011C000E7287108F10A660784000008F00070083B
:1011D0002F3C03185B297008393C031C5B298316DC
:1011E000A301A2012030A1008230A00083126E086A
:1011F0008316A70083126D088316A60083126C085D
:101200008316A50083126B088316A4008A1183122B
:1012100028228A1577088316A0007808A10079088B
:10122000A2007A08A300A5017008A4008A11831205
:10123000A1228A15031083162308AB002208AA00F6
:101240002108A9002008A8007A08AF007908AE009C
:101250007808AD007708AC008A118312C1228A1584
:1012600077088316A4007808A5007908A6007A08F4
:10127000A70003142708AB002608AA002508A90028
:101280002408A800AF01AE014030AD008430AC00AE
:101290008A118312C1228A157A08EE007908ED00BE
:1012A0007808EC007708EB007108F10A6607840003
:1012B0000008F000E72870082E3C031DDF297108A4
:1012C000F10A660784000008F00070082F3C03183C
:1012D000DF297008393C031CDF296A088316A30044
:1012E000831269088316A200831268088316A1007E
:1012F000831267088316A000A701A6012030A5006D
:101300008230A4008A11831228228A157A08EA0002
:101310007908E9007808E8007708E70030307002C3
:101320008316A501A4008A118312A1228A157A08C6
:101330008316A4007908A3007808A2007708A1000A
:1013400083126A088316A800831269088316A7000F
:10135000831268088316A600831267088316A50007
:101360008A11831207248A1503106E088316AB00B6
:1013700083126D088316AA0083126C088316A900D5
:1013800083126B088316A8007A08AF007908AE00B4
:101390007808AD007708AC008A118312C1228A1543
:1013A0007A08EE007908ED007808EC007708EB0089
:1013B0007108F10A660784000008F00065296F0BC8
:1013C000E3298030EC066B08F7006C08F8006D0824
:1013D000F9006E08FA007708E6007808E700790857
:1013E000E8007A08E9008316A400831268088316CF
:1013F000A300831267088316A2008312660883166F
:10140000A100A801C030A7007F30A6008830A50049
:101410008A11831207248A157A08A3007908A2008A
:101420007808A1007708A0000D308316A2008A1169
:1014300083123F218A150A308316A2008A11831273
:101440003F218A15B02A3930840080080319B02A58
:101450003930E600E901E801E701E6080319362A18
:101460006908E90A660784000008EA006A082D3C5A
:10147000031D432A0130E8006908E90A6607840071
:101480000008EA004D2A6A082B3C031D4D2A690812
:10149000E90A660784000008EA006A082F3C03187E
:1014A000672A6A08393C031C672A0A30EB00670880
:1014B000EC008A11D52C8A1530306A027807E700D3
:1014C0006908E90A660784000008EA004D2A680BEB
:1014D0006B2AE709E70A6708F8007808E100073097
:1014E000E60020308316A1008A118312BD218A15DF
:1014F000E60B712AE70167088A1120208A15E70A9E
:101500008316A1008A118312BD218A150430670257
:10151000031D7B2A6108E8001030E9008A112025AC
:101520008A150730E80068088A1120208A15E80A21
:101530008316A1008A118312BD218A150B3068021F
:10154000031D932A05306107E600E7008A11112286
:101550008A1564308316A3008A11831294208A1599
:101560008A11C1258A157A08E5007908E40078080F
:10157000E3007708E200023084006508E9006408AF
:10158000E8006308E7006208E6008A1104268A156D
:101590000530E60066088A1130208A15E60A8316AF
:1015A000A1008A118312BD218A1509306602031D2C
:1015B000CA2A13288A11E6218A158A151B2C2410A1
:1015C000A414BE013E088A113E208A15BE0A831665
:1015D000A1008A118312BD218A1508303E02031D25
:1015E000E22A2414A410BE013E088A114B208A1559
:1015F000BE0A8316A1008A118312BD218A151230FA
:101600003E02031DF42AA414E7018A1111228A154F
:1016100064308316A3008A11831294208A15BD01B9
:101620003D08FA3C031CA52B05303D07BE00E70032
:101630008A1111228A158A11C1258A157A08BC00DF
:101640007908BB007808BA007708B900C101C00169
:10165000BF01BE013C08C5003B08C4003A08C300F6
:101660003908C2008A115F278A15031CA12B831633
:10167000A50183123D088316A4008A118312A122BA
:101680008A153C088316A30083123B088316A20028
:1016900083123A088316A100831239088316A0002A
:1016A0007A08A7007908A6007808A5007708A400A2
:1016B0008A11831228228A157708BE007808BF0095
:1016C0007908C0007A08C1000D308316A1008A1184
:1016D0008312BD218A150A308316A1008A11831254
:1016E000BD218A153D08E800E9018A1120258A15E7
:1016F00020308316A1008A118312BD218A15023081
:1017000084003C08E9003B08E8003A08E700390893
:10171000E6008A1104268A1520308316A1008A115A
:101720008312BD218A15013084004108E900400878
:10173000E8003F08E7003E08E6008A1104268A1503
:10174000A32BFA30BD00BD0A102B0D308316A1006B
:101750008A118312BD218A150A308316A1008A11CD
:101760008312BD218A15E7018A1111228A158A1177
:10177000E6218A158A15312C84011F3083058316D2
:101780009F019D01073083129F00831686128312EA
:101790008616723083168F00061083120610831689
:1017A0008610831286108316861183128611831683
:1017B0008612831286168316811303309B008A11CA
:1017C0008312F9288A152414A414B90139088A113E
:1017D00062208A15B90A8316A1008A118312BD21DD
:1017E0008A1519303902031DE62B3F30831692000B
:1017F0000430831292000C309700950183168611F5
:1018000083128611B9012030BA000430BB008A115E
:10181000D2298A158316061600308312061A013063
:10182000003A031D1C2CC8308316A3008A118312B2
:1018300094208A150028272C0430B900FA3083162A
:10184000A3008A11831294208A15B90B1E2C8A11C9
:10185000E6218A150B10A5010A30A6000B1C372CB7
:10186000DF2A831606168312061E312C0B10241055
:10187000A414B90139088A1180208A15B90A83167F
:10188000A1008A118312BD218A150F303902031D70
:101890003A2CB401B301B201B101B801B701B601EC
:1018A000B501A7012508A80028082602031CC02CA2
:1018B00005302807B900E7008A1111228A158A111C
:1018C000C1258A157A08AC007908AB007808AA000F
:1018D0007708A9008316A501831228088316A4009F
:1018E0008A118312A1228A152C088316A300831261
:1018F0002B088316A20083122A088316A1008312E4
:1019000029088316A0007A08A7007908A60078089D
:10191000A5007708A4008A11831228228A157A0864
:10192000B0007908AF007808AE007708AD0038083D
:10193000C1003708C0003608BF003508BE003008B7
:10194000C5002F08C4002E08C3002D08C2008A114C
:101950005F278A15031CBE2C2C08B4002B08B3008B
:101960002A08B2002908B1003008B8002F08B700D3
:101970002E08B6002D08B5002808A700A80A542C88
:101980002410A4140D308316A1008A118312BD21E6
:101990008A150A308316A1008A118312BD218A1587
:1019A0002708E8001030E9008A1120258A15203028
:1019B0008316A1008A118312BD218A15023084008A
:1019C0003408E9003308E8003208E7003108E6008F
:1019D0008A1104268A1520308316A1008A118312E9
:1019E000BD218A15013084003808E9003708E80075
:1019F0003608E7003508E6008A1104268A152030EB
:101A00008316A1008A118312BD218A152030831606
:101A1000A1008A118312BD218A152708053C0318ED
:101A2000152D05302702A500162DA5012508F03C2F
:101A300003181C2DF030A5000A302507A6002E2C17
:021A4000630041
:02400E00382F49
:00000001FF
;PIC16F88
/Designs/CT01B/SW/1_00/EEPROM.C
0,0 → 1,43
// EEPROM.C - knihovna pro pohodlny zapis a cteni promennych do a z pameti
// EEPROM a to pro ruzne typy promennych.
//
// (c)miho 2002
//
// Historie:
//
// 0.00 Uvodni verze
// 0.01 Formalni zmena
 
 
// Priklad:
//
// int32 MyInt; // deklarace typu (libovolne delky)
// EE_WR(10, MyInt); // zapis promenne MyInt do EEPROM od adresy 10
// EE_RD(10, MyInt); // zpetne nacteni promenne MyInt z EEPROM
//
 
 
// Makro pro jednotne ukladani a vybirani dat (promennych) do a z pameti EEPROM
//
#define EE_WR(EEAddress, Data) EE_Write(EEAddress, &Data, sizeof(Data))
#define EE_RD(EEAddress, Data) EE_Read (EEAddress, &Data, sizeof(Data))
 
 
// Ulozeni promenne do pameti EEPROM
//
void EE_Write(int EEAddress, DataPtr, Len)
{
do
write_eeprom(EEAddress++, *DataPtr++);
while (--Len);
}
 
 
// Nacteni promenne z pameti EEPROM
//
void EE_Read(int EEAddress, DataPtr, Len)
{
do
*DataPtr++ = read_eeprom(EEAddress++);
while (--Len);
}
/Designs/CT01B/SW/1_00/LCD.C
0,0 → 1,311
// LCD modul pro ovladani dvouradkoveho LCD modulu se standardnim Hitachi radicem
// (c)miho 2002,2005
//
// Historie:
//
// 0.00 Uvodni verze se snadnou definici portu LCD displeje
// 0.01 Oprava portu (zapomenute stare identifikatory)
// 0.02 Doplnena moznost pripojeni datoveho portu LCD na libovolne porty
// 0.03 Doplnena procedura lcd_clr pro smazani displeje
//
//
// Funkce:
//
// lcd_init() inicializuje LCD displej a porty, nutno volat jako prvni
//
// lcd_putc(c) zapis snaku do lcd displeje, zpracovava nasledujici ridici znaky
// \f = \x0C - nova stranka - smazani displeje
// \n = \x0A - odradkovani (prechod na druhou radku)
// \b = \x08 - backspace - posunuti kurzoru o 1 pozici zpet
// \r = \x0D - goto home to position 1,1
// \0 .. \7 - definovatelne znaky v pozicich 0 az 7 v CGRAM
// \20 .. \27 - alternativne zapsane znaky (oktalove) v pozicich 0 az 7 CGRAM
// Pozor na to, ze funkce printf konci tisk pokud narazi na \0 (konec retezce)
//
// lcd_gotoxy(x,y) presune kurzor na uvedenou adresu
// nekontroluje parametry
//
// lcd_cursor_on zapne kurzor
// lcd_cursor_off vypne kurzor
//
// lcd_clr smaze displej
//
// lcd_define_char(Index, Def) Makro, ktere definuje znaky od pozice Index obsahem definicniho
// retezce Def. Kazdych 8 znaku retezce Def definuje dalsi znak v CGRAM.
// Kapacita CGRAM je celkem 8 znaku s indexem 0 az 7.
// Na konci se provede lcd_gotoxy(1,1).
// Na konci teto knihovny je priklad pouziti definovanych znaku
//
//
// Definice portu: // Datovy port displeje pripojeny na 4 bity za sebou na jeden port
//
// #define LCD_RS PIN_B2 // rizeni registru LCD displeje
// #define LCD_E PIN_B1 // enable LCD displeje
// #define LCD_DATA_LSB PIN_C2 // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou)
//
//
// Alternativni definice: // Datovy port displeje pripojeny na libovolne 4 bitove porty (vede na kod delsi asi o 25 slov)
//
// #define LCD_RS PIN_B2 // rizeni registru LCD displeje
// #define LCD_E PIN_B1 // enable LCD displeje
// #define LCD_D0 PIN_C2 // D0 - datove bity pripojene na libovolne porty
// #define LCD_D1 PIN_C3 // D1
// #define LCD_D2 PIN_C4 // D2
// #define LCD_D3 PIN_C5 // D3
 
 
 
 
// Privatni sekce, cist jen v pripade, ze neco nefunguje
 
 
 
 
#ifdef LCD_DATA_LSB
// Generovane defince portu pro ucely teto knihovny aby kod generoval spravne IO operace a soucasne
// bylo mozne jednoduse deklarovat pripojene piny LCD displeje pri pouziti teto knihovny. Problem spociva
// v tom, ze se musi spravne ridit smery portu a soucasne datovy port zabira jen 4 bity ze zadaneho portu
//
#define LCD_SHIFT (LCD_DATA_LSB&7) // pocet bitu posuvu datoveho kanalu v datovem portu
#define LCD_PORT (LCD_DATA_LSB>>3) // adresa LCD datoveho portu
#define LCD_TRIS (LCD_PORT+0x80) // adresa prislusneho TRIS registru
#define LCD_MASK (0xF<<LCD_SHIFT) // maska platnych bitu
//
#if LCD_SHIFT>4 // kontrola mezi
#error LCD data port LSB bit not in range 0..4
#endif
#endif
 
 
// Definice konstant pro LCD display
//
#define LCD_CURSOR_ON_ 0x0E // kurzor jako blikajici radka pod znakem
#define LCD_CURSOR_OFF_ 0x0C // zadny kurzor
#define LCD_LINE_2 0x40 // adresa 1. znaku 2. radky
 
 
// Definice rezimu LCD displeje
//
BYTE const LCD_INIT_STRING[4] =
{
0x28, // intrfejs 4 bity, 2 radky, font 5x7
LCD_CURSOR_OFF_, // display on, kurzor off,
0x01, // clear displeje
0x06 // inkrement pozice kurzoru (posun kurzoru doprava)
};
 
 
// Odesle nibble do displeje (posle data a klikne signalem e)
//
void lcd_send_nibble( BYTE n )
{
#ifdef LCD_DATA_LSB
// data jsou za sebou na 4 bitech jednoho portu
*LCD_PORT = (*LCD_PORT & ~LCD_MASK) | ((n << LCD_SHIFT) & LCD_MASK); // nastav datove bity portu a ostatni zachovej
#else
// data jsou na libovolnych 4 bitech libovolnych portu
output_bit(LCD_D0,bit_test(n,0));
output_bit(LCD_D1,bit_test(n,1));
output_bit(LCD_D2,bit_test(n,2));
output_bit(LCD_D3,bit_test(n,3));
#endif
output_bit(LCD_E,1); // vzestupna hrana
delay_us(1); // pockej alespon 450ns od e nebo alespon 195ns od dat
output_bit(LCD_E,0); // sestupna hrana (minimalni perioda e je 1us)
}
 
 
// Odesle bajt do registru LCD
//
// Pokud je Adr=0 .. instrukcni registr
// Pokud je Adr=1 .. datovy registr
//
void lcd_send_byte( BOOLEAN Adr, BYTE n )
{
output_bit(LCD_RS,Adr); // vyber registr
swap(n);
lcd_send_nibble(n); // posli horni pulku bajtu
swap(n);
lcd_send_nibble(n); // posli spodni pulku bajtu
delay_us(40); // minimalni doba na provedeni prikazu
}
 
 
// Provede inicializaci LCD displeje, smaze obsah a nastavi mod displeje
//
// Tato procedura se musi volat pred pouzitim ostatnich lcd_ procedur
//
void lcd_init()
{
 
int i; // pocitadlo cyklu
 
delay_ms(20); // spozdeni pro provedeni startu displeje po zapnuti napajeni
 
#ifdef LCD_DATA_LSB
// data jsou na 4 bitech za sebou, nastav smer pro vsechny dalsi prenosy
*LCD_TRIS = *LCD_TRIS & ~LCD_MASK; // nuluj odpovidajici bity tris registru datoveho portu LCD
#endif
 
output_bit(LCD_RS,0); // nastav jako vystup a nastav klidovy stav
output_bit(LCD_E, 0); // nastav jako vystup a nastav klidovy stav
 
for (i=0; i<3; i++) // nastav lcd do rezimu 8 bitu sbernice
{
delay_ms(2); // muze byt rozdelany prenos dat (2x 4 bity) nebo pomaly povel
lcd_send_nibble(3); // rezim 8 bitu
}
 
delay_us(40); // cas na zpracovani
lcd_send_nibble(2); // nastav rezim 4 bitu (plati od nasledujiciho prenosu)
delay_us(40); // cas na zpracovani
 
for (i=0;i<3;i++) // proved inicializaci (nastaveni modu, smazani apod)
{
lcd_send_byte(0,LCD_INIT_STRING[i]);
delay_ms(2);
}
}
 
 
// Proved presun kurzoru
//
// Pozice 1.1 je domu
//
void lcd_gotoxy( BYTE x, BYTE y)
{
 
BYTE Adr;
 
Adr=x-1;
if(y==2)
Adr+=LCD_LINE_2;
 
lcd_send_byte(0,0x80|Adr);
}
 
 
// Zapis znaku na displej, zpracovani ridicich znaku
//
void lcd_putc( char c)
{
 
switch (c)
{
case '\f' : lcd_send_byte(0,1); // smaz displej
delay_ms(2);
break;
case '\n' : lcd_gotoxy(1,2); break; // presun se na 1. znak 2. radky
case '\r' : lcd_gotoxy(1,1); break; // presun home
case '\b' : lcd_send_byte(0,0x10); break; // posun kurzor o 1 zpet
default : if (c<0x20) c&=0x7; // preklopeni definovatelnych znaku na rozsah 0 az 0x1F
lcd_send_byte(1,c); break; // zapis znak
}
}
 
 
// Zapni kurzor
//
void lcd_cursor_on()
{
lcd_send_byte(0,LCD_CURSOR_ON_);
}
 
 
// Vypni kurzor
//
void lcd_cursor_off()
{
lcd_send_byte(0,LCD_CURSOR_OFF_);
}
 
 
// Smaz displej
//
void lcd_clr()
{
lcd_putc('\f');
}
 
 
// Definice vlastnich fontu
//
// Vlastnich definic muze byt jen 8 do pozic 0 az 7 pameti CGRAM radice lcd displeje
// Pro snadne definovani jsou pripraveny nasledujici definice a na konci souboru je uveden
// priklad pouziti definovanych znaku.
 
 
// Pomocna procedura pro posilani ridicich dat do radice displeje
//
void lcd_putc2(int Data)
{
lcd_send_byte(1,Data);
}
 
 
// Pomocne definice pro programovani obsahu CGRAM
//
#define lcd_define_start(Code) lcd_send_byte(0,0x40+(Code<<3)); delay_ms(2)
#define lcd_define_def(String) printf(lcd_putc2,String);
#define lcd_define_end() lcd_send_byte(0,3); delay_ms(2)
 
 
// Vlastni vykonne makro pro definovani fontu do pozice Index CGRAM s definicnim retezcem Def
//
#define lcd_define_char(Index, Def) lcd_define_start(Index); lcd_define_def(Def); lcd_define_end();
 
 
// Pripravene definice fontu vybranych znaku
// V tabulce nesmi byt 00 (konec retezce v printf()), misto toho davame 80
//
#define LCD_CHAR_BAT100 "\x0E\x1F\x1F\x1F\x1F\x1F\x1F\x1F" /* symbol plne baterie */
#define LCD_CHAR_BAT50 "\x0E\x1F\x11\x11\x13\x17\x1F\x1F" /* symbol polovicni baterie */
#define LCD_CHAR_BAT0 "\x0E\x1F\x11\x11\x11\x11\x11\x1F" /* symbol vybite baterie */
#define LCD_CHAR_UP "\x80\x04\x0E\x15\x04\x04\x04\x80" /* symbol sipka nahoru */
#define LCD_CHAR_DOWN "\x80\x04\x04\x04\x15\x0E\x04\x80" /* symbol Sipka dolu */
#define LCD_CHAR_LUA "\x04\x0E\x11\x11\x1F\x11\x11\x80" /* A s carkou */
#define LCD_CHAR_LLA "\x01\x02\x0E\x01\x1F\x11\x0F\x80" /* a s carkou */
#define LCD_CHAR_HUC "\x0A\x0E\x11\x10\x10\x11\x0E\x80" /* C s hackem */
#define LCD_CHAR_HLC "\x0A\x04\x0E\x10\x10\x11\x0E\x80" /* c s hackem */
#define LCD_CHAR_HUD "\x0A\x1C\x12\x11\x11\x12\x1C\x80" /* D s hackem */
#define LCD_CHAR_HLD "\x05\x03\x0D\x13\x11\x11\x0F\x80" /* d s hackem */
#define LCD_CHAR_LUE "\x04\x1F\x10\x10\x1E\x10\x1F\x80" /* E s carkou */
#define LCD_CHAR_LLE "\x01\x02\x0E\x11\x1F\x10\x0E\x80" /* e s carkou */
#define LCD_CHAR_HUE "\x0A\x1F\x10\x1E\x10\x10\x1F\x80" /* E s hackem */
#define LCD_CHAR_HLE "\x0A\x04\x0E\x11\x1F\x10\x0E\x80" /* e s hackem */
#define LCD_CHAR_LUI "\x04\x0E\x04\x04\x04\x04\x0E\x80" /* I s carkou */
#define LCD_CHAR_LLI "\x02\x04\x80\x0C\x04\x04\x0E\x80" /* i s carkou */
#define LCD_CHAR_HUN "\x0A\x15\x11\x19\x15\x13\x11\x80" /* N s hackem */
#define LCD_CHAR_HLN "\x0A\x04\x16\x19\x11\x11\x11\x80" /* n s hackem */
#define LCD_CHAR_LUO "\x04\x0E\x11\x11\x11\x11\x0E\x80" /* O s carkou */
#define LCD_CHAR_LLO "\x02\x04\x0E\x11\x11\x11\x0E\x80" /* o s carkou */
#define LCD_CHAR_HUR "\x0A\x1E\x11\x1E\x14\x12\x11\x80" /* R s hackem */
#define LCD_CHAR_HLR "\x0A\x04\x16\x19\x10\x10\x10\x80" /* r s hackem */
#define LCD_CHAR_HUS "\x0A\x0F\x10\x0E\x01\x01\x1E\x80" /* S s hackem */
#define LCD_CHAR_HLS "\x0A\x04\x0E\x10\x0E\x01\x1E\x80" /* s s hackem */
#define LCD_CHAR_HUT "\x0A\x1F\x04\x04\x04\x04\x04\x80" /* T s hackem */
#define LCD_CHAR_HLT "\x0A\x0C\x1C\x08\x08\x09\x06\x80" /* t s hackem */
#define LCD_CHAR_LUU "\x02\x15\x11\x11\x11\x11\x0E\x80" /* U s carkou */
#define LCD_CHAR_LLU "\x02\x04\x11\x11\x11\x13\x0D\x80" /* u s carkou */
#define LCD_CHAR_CUU "\x06\x17\x11\x11\x11\x11\x0E\x80" /* U s krouzkem */
#define LCD_CHAR_CLU "\x06\x06\x11\x11\x11\x11\x0E\x80" /* u s krouzkem */
#define LCD_CHAR_LUY "\x02\x15\x11\x0A\x04\x04\x04\x80" /* Y s carkou */
#define LCD_CHAR_LLY "\x02\x04\x11\x11\x0F\x01\x0E\x80" /* y s carkou */
#define LCD_CHAR_HUZ "\x0A\x1F\x01\x02\x04\x08\x1F\x80" /* Z s hackem */
#define LCD_CHAR_HLZ "\x0A\x04\x1F\x02\x04\x08\x1F\x80" /* z s hackem */
 
 
// Priklad pouziti definovanych znaku
//
//
//void lcd_sample()
//{
// lcd_define_char(0,LCD_CHAR_BAT50); // Priklad definice znaku baterie do pozice 0
// lcd_define_char(2,LCD_CHAR_HLE LCD_CHAR_LUI); // Priklad definice znaku e s hackem a I s carkou od pozice 2
// // vsimnete si, ze neni carka mezi retezci s definici (oba retezce definuji
// // jediny definicni retezec)
// printf(lcd_putc,"\fZnaky:\20\22\23"); // priklad vypisu znaku z pozice 0, 2 a 3
// delay_ms(1000);
// lcd_define_char(0,LCD_CHAR_BAT0); // Predefinovani tvaru znaku v pozici 0
// delay_ms(1000);
//}