├── .gitignore
├── LCD
├── CONNECTIONS
├── testlcd.c
├── lcd.h
└── lcd.c
├── TODO
├── README
├── COPYING
├── KEYPAD
├── keypad.c
└── keypad.h
├── 24xx
├── 24xx.c
└── 24xx.h
├── ADXL335
├── adxl335.c
└── adxl335.h
├── R303A
├── r303a.c
└── r303a.h
├── ADC
├── adc.c
└── adc.h
├── PCF8591
├── pcf8591.c
└── pcf8591.h
├── HC-05
├── hc05.c
└── hc05.h
├── RFID
├── rfid.h
└── rfid.c
├── UART
├── testuart.c
├── uart.h
└── uart.c
├── Test
├── testi2c.c
└── test.c
├── IO
├── io.h
└── io.c
├── TIMER
├── timer.h
└── timer.c
├── I2C
├── i2c.h
└── i2c.c
├── ADC0804
├── adc0804.h
└── adc0804.c
└── LICENCE
/.gitignore:
--------------------------------------------------------------------------------
1 | .txt
--------------------------------------------------------------------------------
/LCD/CONNECTIONS:
--------------------------------------------------------------------------------
1 | 8051 & LCD (16x2) LCD Connections
2 |
3 | EN (Enable) : P1.4
4 | RS (Register Select) : P1.5
5 | D4 (Data Bit 4) : P1.0
6 | D5 (Data Bit 5) : P1.1
7 | D6 (Data Bit 6) : P1.2
8 | D7 (Data Bit 7) : P1.3
9 |
10 |
--------------------------------------------------------------------------------
/TODO:
--------------------------------------------------------------------------------
1 | Driver Development
2 |
3 | Low Level
4 | - SPI
5 | - PWM
6 |
7 | Device Level
8 | - DS1307
9 | - PCF8591
10 | - ADC 0804
11 |
12 | Not Tested
13 | - DS1307
14 | - PCF8591
15 | - ADXL335
16 | - HC-05
17 | - ADC 0804
18 |
19 | Issues
20 | - LCD 4 BIT
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | Library for 8051 is free software for 8051 family MCU's
2 |
3 | For Copying and licence information pleae see 'COPYING' and 'LICENCE' file
4 |
5 | Development Tools Required
6 | Toolchain : SDCC (Opensource toolchain for 8051/PIC Controllers)
7 | Text Editor : Programmer's notepad Prefered (Use any text editor) or Use Codeblocks with SDCC (An IDE for SDCC)
8 | Build Tool : GNU Make 3.81 (Opensource software build automation tool for C/C++ Developers)
9 | Flasher : Flash Magic (Flashing tool from NXP Semiconductor)
10 |
11 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | This program is free software: you can redistribute it and/or modify
2 | it under the terms of the GNU General Public License as published by
3 | the Free Software Foundation, either version 3 of the License, or
4 | (at your option) any later version.
5 |
6 | This program is distributed in the hope that it will be useful,
7 | but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 | GNU General Public License for more details.
10 |
11 | You should have received a copy of the GNU General Public License
12 | along with this program. If not, see
13 |
14 | For more information see LICENCE file
--------------------------------------------------------------------------------
/KEYPAD/keypad.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 |
20 | /***
21 | ** File : keypad.c
22 | ** Author : Sriharsha
23 | ** Website : www.zuna.in
24 | ** Email : helpzuna@gmail.com
25 | ** Description: This is the keypad driver for 8051 family MCU's
26 | ***/
27 |
28 |
29 |
--------------------------------------------------------------------------------
/24xx/24xx.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 |
20 | /***
21 | ** File : 24xx.c
22 | ** Author : Sriharsha
23 | ** Website : www.zuna.in
24 | ** Email : helpzuna@gmail.com
25 | ** Description: This is the EEPROM(24xx Series) driver file for 8051 family MCU's
26 | ***/
27 |
28 |
--------------------------------------------------------------------------------
/ADXL335/adxl335.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 | /***
20 | ** File : adxl335.c
21 | ** Author : Sriharsha
22 | ** Website : www.zuna.in
23 | ** Email : helpzuna@gmail.com
24 | ** Description: This is driver for ADXL335 Accelerometer library for 8051 family MCU's
25 | ***/
26 |
27 |
--------------------------------------------------------------------------------
/R303A/r303a.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 |
20 | /***
21 | ** File : r303a.c
22 | ** Author : Sriharsha
23 | ** Website : www.zuna.in
24 | ** Email : helpzuna@gmail.com
25 | ** Description: This is the R303A Finger Print Scanner driver for 8051 family MCU's
26 | ***/
27 |
28 | #include "r303a.h"
29 |
30 |
--------------------------------------------------------------------------------
/ADC/adc.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 | /***
20 | ** File : adc.c
21 | ** Author : Sriharsha
22 | ** Website : www.zuna.in
23 | ** Email : helpzuna@gmail.com
24 | ** Description: This is include file for ADC library for 8051 family MCU's
25 | ***/
26 |
27 | double Raw2Voltage(int __val)
28 | {
29 | return ADC_TO_VOLTAGE(__val);
30 | }
31 |
--------------------------------------------------------------------------------
/24xx/24xx.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 |
20 | /***
21 | ** File : 24xx.h
22 | ** Author : Sriharsha
23 | ** Website : www.zuna.in
24 | ** Email : helpzuna@gmail.com
25 | ** Description: This is the EEPROM(24xx Series) driver include file for 8051 family MCU's
26 | ***/
27 |
28 | #ifndef __24xx_h__
29 | #define __24xx_h__
30 |
31 | #define 24XX_ADDRESS 0x00
32 |
33 | #define 24xxBegin(val) i2cBegin(val)
34 | #define 24xxBusy() i2cavailable()
35 | #define 24xxWrite(val1,val2) i2cWrite(val1,val2)
36 | #define 24xxRead(val) i2cRead(val)
37 | #define 24xxAddress(val) i2csetAdd(val)
38 |
39 | #endif
40 |
41 |
--------------------------------------------------------------------------------
/PCF8591/pcf8591.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 | /***
19 | ** File : pcf8591.c
20 | ** Author : Sriharsha
21 | ** Website : www.zuna.in
22 | ** Email : helpzuna@gmail.com
23 | ** Description: This is the PCF8591 driver file with 8051
24 | ***/
25 |
26 | <<<<<<< HEAD
27 |
28 | void begin(void)
29 | {
30 | i2cbegin(PCF8591_SLAVE_ADDRESS);
31 | }
32 |
33 | int analogRead(unsigned char ch)
34 | {
35 | if(ch == ADC_CH_0)
36 | return i2cread(ADC_CH_0);
37 | else if(ch == ADC_CH_1)
38 | return i2cread(ADC_CH_1);
39 | else if(ch == ADC_CH_2)
40 | return i2cread(ADC_CH_2);
41 | else if(ch == ADC_CH_3)
42 | return i2cread(ADC_CH_3);
43 | }
44 |
45 | void analogWrite(int __val)
46 | {
47 |
48 | }
49 |
50 | =======
51 | >>>>>>> 7b87dc8e7aacf5e30416c903205ba0a92e66d671
52 |
--------------------------------------------------------------------------------
/HC-05/hc05.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 | /***
19 | ** File : hc05.c
20 | ** Author : Sriharsha
21 | ** Website : www.zuna.in
22 | ** Email : helpzuna@gmail.com
23 | ** Description: This is the HC-05 Bluetooth module driver for 8051 family MCU's
24 | ***/
25 |
26 | #include "hc05.h"
27 |
28 | void HC05Begin(unsigned long osc,unsigned long baud)
29 | {
30 | Serialbegin(osc,baud);
31 | }
32 |
33 | void HC05Write(char c)
34 | {
35 | Serialwrite(c);
36 | }
37 |
38 | void HC05Print(char *ptr)
39 | {
40 | Serialprint(ptr);
41 | }
42 |
43 | unsigned char HC05Test(void)
44 | {
45 | return 0;
46 | }
47 |
48 | unsigned char HC05Read(void)
49 | {
50 | return Serialread();
51 | }
52 |
53 | unsigned char HC05Available(void)
54 | {
55 | return Serialavailable();
56 | }
57 |
58 | /*unsigned char* HC05GetVersion(void)
59 | {
60 | }*/
61 |
62 |
63 |
--------------------------------------------------------------------------------
/PCF8591/pcf8591.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 | /***
19 | ** File : pcf8591.h
20 | ** Author : Sriharsha
21 | ** Website : www.zuna.in
22 | ** Email : helpzuna@gmail.com
23 | ** Description: This is the include file for PCF8591 with 8051
24 | ***/
25 |
26 | #ifndef __pcf8591_h__
27 | #define __pcf8591_h__
28 |
29 | #define PCF8591_SLAVE_ADDRESS 0x90
30 |
31 | int analogRead(unsigned char);
32 | <<<<<<< HEAD
33 | void analogWrite(int);
34 | =======
35 | void analogWrite(unsigned int);
36 | >>>>>>> 7b87dc8e7aacf5e30416c903205ba0a92e66d671
37 | void begin(void);
38 |
39 | #define ADC_CH_0 0
40 | #define ADC_CH_1 1
41 | #define ADC_CH_2 2
42 | #define ADC_CH_3 3
43 |
44 | #define ADC_CH0_REG_ADDRESS 0
45 | #define ADC_CH1_REG_ADDRESS 1
46 | #define ADC_CH2_REG_ADDRESS 2
47 | #define ADC_CH3_REG_ADDRESS 3
48 |
49 | #define DAC_REG_ADDRESS 0x40
50 |
51 | #endif
--------------------------------------------------------------------------------
/ADC/adc.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 | /***
20 | ** File : adc.h
21 | ** Author : Sriharsha
22 | ** Website : www.zuna.in
23 | ** Email : helpzuna@gmail.com
24 | ** Description: This is include file for ADC library for 8051 family MCU's
25 | ***/
26 |
27 | #ifndef __adc_h__
28 | #define __adc_h__
29 |
30 | #define ADC_RES_BITS 10
31 |
32 | #if ADC_RES_BITS == 12
33 | #define ADC_RES_VAL 4095
34 | #elif ADC_RES_BITS == 10
35 | #define ADC_RES_VAL 1023
36 | #elif ADC_RES_BITS == 8
37 | #define ADC_RES_VAL 255
38 | #endif
39 |
40 | #define Vref 3.3
41 | #define AdcRefVoltage (Vref * 1000) // In milli volts
42 | #define ADC_TO_VOLTAGE(val) val * (AdcRefVoltage / ADC_RES_VAL)
43 |
44 | extern double Raw2Voltage(void); // Return in milli volts
45 |
46 | #endif
47 |
48 |
--------------------------------------------------------------------------------
/ADXL335/adxl335.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 | /***
20 | ** File : adxl335.h
21 | ** Author : Sriharsha
22 | ** Website : www.zuna.in
23 | ** Email : helpzuna@gmail.com
24 | ** Description: This is include file for ADXL335 Accelerometer library for 8051 family MCU's
25 | ***/
26 |
27 | // To read Raw Values
28 | extern int Adxl335getPureRawX(void);
29 | extern int Adxl335getPureRawY(void);
30 | extern int Adxl335getPureRawZ(void);
31 |
32 | // To read Calculated raw values (Bias voltage is considered)
33 | extern double Adxl335getCalRawX(void);
34 | extern double Adxl335getCalRawY(void);
35 | extern double Adxl335getCalRawZ(void);
36 |
37 | // To read Voltage from X,Y,Z
38 | extern double Adxl335getCalVoltageX(void);
39 | extern double Adxl335getCalVoltageY(void);
40 | extern double Adxl335getCalVoltageZ(void);
41 |
42 | // To read g Values
43 | extern double Adxl335get_g_X(void);
44 | extern double Adxl335get_g_Y(void);
45 | extern double Adxl335get_g_Z(void);
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/HC-05/hc05.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 | /***
19 | ** File : hc05.h
20 | ** Author : Sriharsha
21 | ** Website : www.zuna.in
22 | ** Email : helpzuna@gmail.com
23 | ** Description: This is include file of HC-05 Driver for 8051 family MCU's
24 | ***/
25 |
26 | #ifndef __hc05_h__
27 | #define __hc05_h__
28 |
29 | #include "uart.h"
30 |
31 | #define COMMAND_TEST_COMMUNICATION "AT"
32 | #define COMMAND_GET_VERSION "AT+VERSION?"
33 | #define COMMAND_SET_DEFAULT "AT+ORGL"
34 | #define COMMAND_GET_ADDRESS "AT+ADDR?"
35 | #define COMMAND_GET_MOD_NAME "AT+NAME?"
36 | #define COMMAND_SET_MOD_NAME "AT+NAME=" // AT+NAME= ; here param is module name
37 | #define COMMAND_GET_DEV_NAME "AT+RNAME?" // AT+RNAME? ; param is address of bluetooth device
38 | #define COMMAND_GET_MOD_MODE "AT+ROLE?"
39 | #define COMMAND_SET_MOD_MODE "AT+ROLE="
40 |
41 | #define HC05_BAUDRATE 38400
42 |
43 |
44 | #endif
45 |
46 |
--------------------------------------------------------------------------------
/RFID/rfid.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 | /***
19 | ** File : rfid.h
20 | ** Author : Sriharsha
21 | ** Website : www.zuna.in
22 | ** Email : helpzuna@gmail.com
23 | ** Description: This is the RFID (UART Interface) driver include file for 8051 uart driver
24 | ***/
25 |
26 | #ifndef __rfid_h__
27 | #define __rfid_h__
28 |
29 | //#define LINEF_TERMINATION
30 | #define COUNT_TERMINATION
31 |
32 |
33 | #ifdef LINEF_TERMINATION
34 | #ifdef COUNT_TERMINATION
35 | #error "Both LINEF_TERMINATION and COUNT_TERMINATION are defined"
36 | #endif
37 | #endif
38 |
39 | #ifdef COUNT_TERMINATION
40 | #ifdef LINEF_TERMINATION
41 | #error "Both LINEF_TERMINATION and COUNT_TERMINATION are defined"
42 | #endif
43 | #endif
44 |
45 |
46 | #define RFID_FRAME_LENGTH 9
47 |
48 | #define RFID_DB_SIZE 10
49 |
50 | #ifdef COUNT_TERMINATION
51 | #define RFID_CHAR_COUNT 9
52 | #endif
53 |
54 |
55 | extern unsigned char checkSwipe(void);
56 | extern unsigned char checkDatabase(void);
57 | extern char* getName(void);
58 | extern char* getTagNo(void);
59 |
60 |
61 | #endif
--------------------------------------------------------------------------------
/UART/testuart.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 | /***
19 | ** File : testuart.c
20 | ** Author : Sriharsha
21 | ** Website : www.zuna.in
22 | ** Email : helpzuna@gmail.com
23 | ** Description: This is the test code for 8051 uart driver
24 | ***/
25 |
26 | #include "uart.h"
27 |
28 | #define OSC_FREQ 11059200
29 | #define BAUD_RATE 9600
30 |
31 | #define NEW_LINE_THRESHOLD 3
32 |
33 | /*** Function : main
34 | ** Parameters : None
35 | ** Return : int
36 | ** Description : It is the entry point of program
37 | **/
38 | int main(void)
39 | {
40 | SetOsc(OSC_FREQ); // Set Oscillator Freq
41 | Serialbegin(BAUD_RATE); // Set Baud Rate
42 | Serialflush(); // Clear the buffers
43 | Serialprint("uart test\n\r"); // Print a string
44 | setSerialinterrupt(); // Enable Serial Interrupt
45 | while(1)
46 | {
47 | while(uartNewLineCount
2 | #include "uart.h"
3 |
4 | #define SDA P0_0
5 | #define SCL P0_1
6 |
7 | void I2CInit(){
8 | SDA = 1;
9 | SCL = 1;
10 | }
11 |
12 | void I2CStart(){
13 | SCL = 1;
14 | SDA = 0;
15 | SCL = 0;
16 | }
17 |
18 | void I2CRestart(){
19 | SDA = 1;
20 | SCL = 1;
21 | SDA = 0;
22 | }
23 |
24 | void I2CStop(){
25 | SDA = 0;
26 | SCL = 1;
27 | SDA = 1;
28 | }
29 |
30 | void I2CAck(){
31 | SDA = 0;
32 | SCL = 1;
33 | SCL = 0;
34 | }
35 |
36 | void I2CNak(){
37 | SDA = 1;
38 | SCL = 1;
39 | SCL = 0;
40 | }
41 |
42 | unsigned char I2CSend(unsigned char Data){
43 | unsigned char i, ack_bit;
44 | for(i=0;i<8;i++){
45 | SCL = 0;
46 | if ((Data & 0x80) == 0)
47 | SDA = 0;
48 | else
49 | SDA = 1;
50 | SCL = 1;
51 | Data<<=1;
52 | }
53 | SCL = 0;
54 | ack_bit = SDA;
55 | SCL = 1;
56 | SCL = 0;
57 | return !ack_bit;
58 | }
59 |
60 | unsigned char I2CRead(){
61 | unsigned char i, Data=0;
62 | for(i=0;i<8;i++){
63 | SCL = 0;
64 | SCL = 1;
65 | if(SDA)
66 | Data |=1;
67 | if(i<7)
68 | Data<<=1;
69 | }
70 | SCL = 0;
71 | SDA = 1;
72 | return Data;
73 | }
74 |
75 | int main()
76 | {
77 | unsigned char i, a[7], ack;
78 | unsigned int j;
79 | I2CInit();
80 | Serialbegin(9600);
81 | Serialprint("Test Hello I2C");
82 | /* Writing on i2c */
83 | I2CStart();
84 | I2CSend(0xD0);
85 | I2CSend(0x00);
86 | I2CSend(0x00);
87 | I2CSend(0x00);
88 | I2CSend(0x00);
89 | I2CSend(0x03);
90 | I2CSend(0x01);
91 | I2CSend(0x01);
92 | I2CSend(0x13);
93 | I2CStop();
94 |
95 | while(1){
96 | /* reading on I2c */
97 | /* Dummy Write */
98 | I2CStart();
99 | I2CSend(0xD0);
100 | I2CSend(0x00);
101 | /* Actual read */
102 | I2CRestart();
103 | I2CSend(0xD1);
104 | for(i=0;i<7;i++){
105 | a[i]=I2CRead();
106 | if(i==6)
107 | I2CNak();
108 | else
109 | I2CAck();
110 | }
111 | I2CStop();
112 | SerialIntWrite(a[2]);
113 | Serialwrite(':');
114 | SerialIntWrite(a[1]);
115 | Serialwrite(':');
116 | SerialIntWrite(a[0]);
117 | SerialIntWrite(a[4]);
118 | Serialwrite('-');
119 | SerialIntWrite(a[5]);
120 | Serialwrite('-');
121 | SerialIntWrite(a[6]);
122 | for(j=65535;j>0;j--);
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/Test/test.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 | /***
19 | ** File : testuart.c
20 | ** Author : Sriharsha
21 | ** Website : www.zuna.in
22 | ** Email : helpzuna@gmail.com
23 | ** Description: This is the test code for 8051 uart driver
24 | ***/
25 |
26 | #include "uart.h"
27 | #include "i2c.h"
28 |
29 |
30 | #define OSC_FREQ (unsigned long)11059200
31 | #define BAUD_RATE 9600
32 |
33 | #define NEW_LINE_THRESHOLD 3
34 |
35 | /*** Function : main
36 | ** Parameters : None
37 | ** Return : int
38 | ** Description : It is the entry point of program
39 | **/
40 | int main(void)
41 | {
42 | SetOsc(OSC_FREQ); // Set Oscillator Freq
43 | Serialbegin(BAUD_RATE); // Set Baud Rate
44 | Serialprint("I2C Test\n\r"); // Print a string
45 | if(i2cBegin(0xA0) == 1)
46 | Serialprint("Device Detected\n\r"); // Print a string
47 | else
48 | Serialprint("Device Not Detected\n\r"); // Print a string*/
49 | Serialflush(); // Clear the buffers
50 |
51 | setSerialinterrupt(); // Enable Serial Interrupt
52 | while(1)
53 | {
54 | while(uartNewLineCount.
16 | /**************************************************************************************************************/
17 |
18 |
19 | /***
20 | ** File : io.h
21 | ** Author : Sriharsha
22 | ** Website : www.zuna.in
23 | ** Email : helpzuna@gmail.com
24 | ** Description: This is include file for io library for 8051 family MCU's
25 | ***/
26 | #ifndef __io_h__
27 | #define __io_h__
28 |
29 | #ifndef SDCC
30 | #define SDCC 0
31 | #endif
32 | #ifndef KEIL
33 | #define KEIL 1
34 | #endif
35 |
36 | #ifndef TOOLCHAIN
37 | #define TOOLCHAIN SDCC
38 | #endif
39 |
40 | #if TOOLCHAIN == SDCC
41 | #include <8051.h> // 8051 Peripheral Address preprocessor file
42 | #elif TOOLCHAIN == KEIL
43 | #include
44 | #else
45 | #error "Invalid Toolchain, Please check 'TOOLCHAIN' macro (SDCC/KEIL)"
46 | #endif
47 |
48 | #include
49 |
50 | #define PORT0DIR P0
51 | #define PORT1DIR P1
52 | #define PORT2DIR P2
53 | #define PORT3DIR P3
54 |
55 | #define PORT0OUT P0
56 | #define PORT1OUT P1
57 | #define PORT2OUT P2
58 | #define PORT3OUT P3
59 |
60 | #define PORT0IN P0
61 | #define PORT1IN P1
62 | #define PORT2IN P2
63 | #define PORT3IN P3
64 |
65 | #define HIGH 1
66 | #define LOW 0
67 | #define OUTPUT 1
68 | #define INPUT 0
69 |
70 | #define IO_MAX 7
71 |
72 | // Prototypes
73 |
74 | extern void digitalWrite(unsigned char,unsigned char); // Pin Number, Pin State (HIGH,LOW)
75 | extern unsigned char digitalRead(unsigned char); // Pin Number
76 | extern void pinMode(unsigned char,unsigned char); // Pin Number, Mode-> OUTPUT,INPUT
77 |
78 | #endif
79 |
--------------------------------------------------------------------------------
/RFID/rfid.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 | /***
19 | ** File : rfid.c
20 | ** Author : Sriharsha
21 | ** Website : www.zuna.in
22 | ** Email : helpzuna@gmail.com
23 | ** Description: This is the RFID (UART Interface) driver for 8051 family MCU's
24 | ***/
25 |
26 | #include "uart.h"
27 | #include "rfid.h"
28 |
29 | #if TOOLCHAIN == SDCC
30 | __code unsigned char *ID_DB[] = {"12345","45678"};
31 | __code unsigned char *NM_DB[] = {"Name1","Name2"};
32 |
33 | #elif TOOLCHAIN == KEIL
34 | code unsigned char *ID_DB[] = {"12345","45678"};
35 | code unsigned char *NM_DB[] = {"Name1","Name2"};
36 | #endif
37 |
38 |
39 | volatile unsigned char FrameIndexDB = 0;
40 | volatile unsigned char FrameIndexPt = 0;
41 |
42 | unsigned char checkSwipe(void)
43 | {
44 | #ifdef COUNT_TERMINATION
45 | if(uartReadCount == RFID_CHAR_COUNT)
46 | return 1;
47 | else
48 | return 0;
49 | #endif
50 |
51 | #ifdef LINEF_TERMINATION
52 | if(uartNewLineFlag)
53 | return 1;
54 | else
55 | return 0;
56 | #endif
57 | }
58 |
59 | unsigned char checkDatabase(void)
60 | {
61 | unsigned char i;
62 | unsigned char j;
63 | unsigned char tempCount;
64 | for(i=0;i<=RFID_DB_SIZE;i++)
65 | {
66 | for(j=0;j<=RFID_DB_SIZE;j++)
67 | {
68 | if(ID_DB[i][j] == uartReadBuffer[j])
69 | tempCount++;
70 | }
71 | if(tempCount == RFID_FRAME_LENGTH)
72 | {
73 | FrameIndexDB = i;
74 | FrameIndexPt = j;
75 | return 1;
76 | }
77 | else
78 | tempCount = 0;
79 | }
80 | }
81 |
82 | char* getName(void)
83 | {
84 | return NM_DB[FrameIndexDB][FrameIndexPt];
85 | }
86 |
87 | char* getTagNo(void)
88 | {
89 | return ID_DB[FrameIndexDB][FrameIndexPt];
90 | }
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/KEYPAD/keypad.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 |
20 | /***
21 | ** File : keypad.h
22 | ** Author : Sriharsha
23 | ** Website : www.zuna.in
24 | ** Email : helpzuna@gmail.com
25 | ** Description: This is the Keypad include file for 8051 family MCU's
26 | ***/
27 | #ifndef __keypad_h__
28 | #define __keypad_h__
29 |
30 | #ifndef KEYPAD_HEX
31 | #define KEYPAD_HEX
32 | #endif
33 |
34 | /*
35 | #ifndef KEYPAD_DEC
36 | #define KEYPAD_DEC
37 | #endif
38 | */
39 |
40 | // Pin Definitions
41 | #define KEYPAD_ROW_0_DIR P1
42 | #define KEYPAD_ROW_0_OUT P1
43 | #define KEYPAD_ROW_0_IN P1
44 | #define KEYPAD_ROW_0_BIT 1 << 0
45 |
46 | #define KEYPAD_ROW_1_DIR P1
47 | #define KEYPAD_ROW_1_OUT P1
48 | #define KEYPAD_ROW_1_IN P1
49 | #define KEYPAD_ROW_1_BIT 1 << 1
50 |
51 | #define KEYPAD_ROW_2_DIR P1
52 | #define KEYPAD_ROW_2_OUT P1
53 | #define KEYPAD_ROW_2_IN P1
54 | #define KEYPAD_ROW_2_BIT 1 << 2
55 |
56 | #define KEYPAD_ROW_3_DIR P1
57 | #define KEYPAD_ROW_3_OUT P1
58 | #define KEYPAD_ROW_3_IN P1
59 | #define KEYPAD_ROW_3_BIT 1 << 3
60 |
61 |
62 | #define KEYPAD_COL_0_DIR P1
63 | #define KEYPAD_COL_0_OUT P1
64 | #define KEYPAD_COL_0_IN P1
65 | #define KEYPAD_COL_0_BIT 1 << 4
66 |
67 | #define KEYPAD_COL_1_DIR P1
68 | #define KEYPAD_COL_1_OUT P1
69 | #define KEYPAD_COL_1_IN P1
70 | #define KEYPAD_COL_1_BIT 1 << 5
71 |
72 | #define KEYPAD_COL_2_DIR P1
73 | #define KEYPAD_COL_2_OUT P1
74 | #define KEYPAD_COL_2_IN P1
75 | #define KEYPAD_COL_2_BIT 1 << 6
76 |
77 | #ifdef KEYPAD_HEX
78 | #define KEYPAD_COL_3_DIR P1
79 | #define KEYPAD_COL_3_OUT P1
80 | #define KEYPAD_COL_3_IN P1
81 | #define KEYPAD_COL_3_BIT 1 << 7
82 | #endif
83 |
84 |
85 |
86 | #endif
--------------------------------------------------------------------------------
/LCD/testlcd.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Foobar. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 | /***
20 | ** File : testlcd.c
21 | ** Author : Sriharsha
22 | ** Website : www.zuna.in
23 | ** Email : helpzuna@gmail.com
24 | ** Description: This is test code for 8051 LCD driver
25 | ***/
26 |
27 | #include "lcd.h" // Include LCD driver
28 |
29 | #define LCD_REFRESH_DELAY 5000 // LCD Refresh rate in milliseconds
30 |
31 | // Strings to display
32 | // If 20x2 LCD define below string
33 | #if _LCD_TYPE_ == 1
34 | #define String1 " Hello World "
35 | #define String2 " Hai 8051 "
36 | #define String3 " This is "
37 | #define String4 " LCD TEST "
38 | // Otherwise if 16x2 define below string
39 | #elif _LCD_TYPE_ == 2
40 | #define String1 " Hello World "
41 | #define String2 " Hai 8051 "
42 | #endif
43 |
44 |
45 | /** Function : main
46 | * Parameters : None
47 | * Return : int
48 | * Description : It is the entry point of program
49 | **/
50 | int main(void)
51 | {
52 | lcdBegin(); // Initiate the LCD
53 | while(1)
54 | {
55 | #if _LCD_TYPE_ == 1
56 | lcdSetCursor(1,0);
57 | lcdPrint(String1);
58 | __delay_ms__(LCD_REFRESH_DELAY);
59 | lcdSetCursor(2,0);
60 | lcdPrint(String2);
61 | __delay_ms__(LCD_REFRESH_DELAY);
62 | lcdSetCursor(3,0);
63 | lcdPrint(String3);
64 | __delay_ms__(LCD_REFRESH_DELAY);
65 | lcdSetCursor(4,0);
66 | lcdPrint(String4);
67 | __delay_ms__(LCD_REFRESH_DELAY);
68 | lcdClear();
69 | __delay_ms__(LCD_REFRESH_DELAY);
70 | #elif _LCD_TYPE_ == 2
71 | lcdSetCursor(1,0);
72 | lcdPrint(String1);
73 | __delay_ms__(LCD_REFRESH_DELAY);
74 | lcdSetCursor(2,0);
75 | lcdPrint(String2);
76 | __delay_ms__(LCD_REFRESH_DELAY);
77 | lcdClear();
78 | __delay_ms__(LCD_REFRESH_DELAY);
79 | #endif
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/TIMER/timer.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 | /***
19 | ** File : timer.h
20 | ** Author : Sriharsha
21 | ** Website : www.zuna.in
22 | ** Email : helpzuna@gmail.com
23 | ** Description: This is the hardware timer driver include file for 8051 family MCU's
24 | ***/
25 |
26 | #ifndef __timer_h__
27 | #define __timer_h__
28 |
29 | #ifndef SDCC
30 | #define SDCC 0
31 | #endif
32 | #ifndef KEIL
33 | #define KEIL 1
34 | #endif
35 |
36 | #ifndef TOOLCHAIN
37 | #define TOOLCHAIN SDCC
38 | #endif
39 |
40 | #if TOOLCHAIN == SDCC
41 | #include <8051.h> // 8051 Peripheral Address preprocessor file
42 | #elif TOOLCHAIN == KEIL
43 | #include
44 | #else
45 | #error "Invalid Toolchain, Please check 'TOOLCHAIN' macro (SDCC/KEIL)"
46 | #endif
47 |
48 | #define ENABLE_TIMER_0
49 | //#define ENABLE_TIMER_1
50 | //#define ENABLE_TIMER_2
51 |
52 | #define TIMER0 0
53 | #define TIMER1 1
54 | #define TIMER2 2
55 |
56 |
57 | #define ENABLE_TIMER_0_INTERRUPT
58 | //#define ENABLE_TIMER_1_INTERRUPT
59 | //#define ENABLE_TIMER_2_INTERRUPT
60 |
61 | #define _timer_0_1_mode_2_calc(__val,__freq) 65535 - ((__val*1000) / (12/__freq))
62 |
63 | // Timer 0,1 Modes
64 | #define TIMER_0_1_MODE_0 0x00
65 | #define TIMER_0_1_MODE_1 0x00
66 | #define TIMER_0_1_MODE_2 0x00
67 | #define TIMER_0_1_MODE_3 0x00
68 |
69 |
70 | extern timerBegin(unsigned char,unsigned char,unsigned long);//,unsigned char); // Timer Number, Timer Value (in milliseconds), Timer Mode, Oscillator Frequency
71 | extern timerStart(unsigned char,unsigned char); // Timer Number, Interrupts (Enabled,Disabled);
72 | extern timerStop(unsigned char); // Timer Number (It will also disable interrupts)
73 |
74 |
75 | #ifdef ENABLE_TIMER_0_INTERRUPT
76 |
77 | #if TOOLCHAIN == SDCC
78 | extern void timer0ISR(void) __interrupt(1);
79 | #elif TOOLCHAIN == KEIL
80 | extern void timer0ISR(void) interrupt(1);
81 | #else
82 | #error "Invalid Toolchain, Please check 'TOOLCHAIN' macro (SDCC/KEIL)"
83 | #endif
84 | extern unsigned int TimerCount0;
85 |
86 | #endif
87 |
88 | /*extern unsigned int TimerCount1;
89 | extern unsigned int TimerCount2;*/
90 | #endif
91 |
92 | #endif
--------------------------------------------------------------------------------
/R303A/r303a.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 | /***
19 | ** File : r303a.h
20 | ** Author : Sriharsha
21 | ** Website : www.zuna.in
22 | ** Email : helpzuna@gmail.com
23 | ** Description: This is the R1303A Fingerprint Driver include file for 8051 family MCU's
24 | ***/
25 |
26 | #ifndef __r303a_h__
27 | #define __r303a_h__
28 |
29 | #ifndef SDCC
30 | #define SDCC 0
31 | #endif
32 | #ifndef KEIL
33 | #define KEIL 1
34 | #endif
35 |
36 | #ifndef TOOLCHAIN
37 | #define TOOLCHAIN SDCC
38 | #endif
39 |
40 | #if TOOLCHAIN == SDCC
41 | #include <8051.h> // 8051 Peripheral Address preprocessor file
42 | #elif TOOLCHAIN == KEIL
43 | #include
44 | #else
45 | #error "Invalid Toolchain, Please check 'TOOLCHAIN' macro (SDCC/KEIL)"
46 | #endif
47 |
48 | // Acknowledgements
49 | #define EXEC_COMPLETE 0x00
50 | #define ERROR_RECV_DATA_PACK 0x01
51 | #define NO_FINGER_ON_SENSOR 0x02
52 | #define FAIL_TO_ENROLL_FINGER 0x03
53 | #define FAIL_OVER_DISORDER_FINGER_IMAGE 0x06
54 | #define FAIL_LACKNESS_CHAR_POINT_FINGER_IMAGE 0x07
55 | #define FINGER_MIS_MATCH 0x08
56 | #define FAIL_TO_FIND_MATCH_FINGER 0x09
57 | #define FAIL_TO_COMBINE_CHAR_FILE 0x0A
58 | #define ADDRESS_PAGE_ID_EXCEEDS_LIMIT 0x0B
59 | #define ERROR_READING_TEMPLATE 0x0C
60 | #define ERROR_UPLOAD_TEMPLATE 0x0D
61 | #define CANT_RECV_DATA_FOLLW_DATA_PACK 0x0E
62 | #define ERROR_TO_UPLOAD_IMAGE 0x0F
63 | #define FAIL_TO_DELETE_FROM_LIB 0x10
64 | #define FAIL_TO_CLEAR_FING_LIB 0x11
65 | #define WRONG_PASSWORD 0x13
66 | #define FAIL_TO_GEN_IMAGE_FOR_LACKNESS_PRIMARY_IMAGE 0x15
67 | #define ERRROR_WHILE_WRITING_TO_FLASH 0x18
68 | #define NO_DEFINITION_ERROR 0x19
69 | #define INVALID_REG_NUMBER 0x1A
70 | #define INCORRET_CONF_REG 0x1B
71 | #define WRONG_NOTEPAD_PAGE_NUMBER 0x1C
72 | #define FAIL_TO_OPERATE_COM_PORT 0x1D
73 |
74 | /** PACKET FORMAT
75 |
76 | /*** [Header (2 Bytes)] [ Adder (4 Bytes)] [PACKAGE_ID (1 Byte)] [PACKAGE_LEN (2 Bytes)] [PACKAGE_CONTENT ()] [CHECKSUM (2 Byte)] ***/
77 |
78 | // Prototypes
79 |
80 |
81 |
82 | #endif
--------------------------------------------------------------------------------
/TIMER/timer.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 | /***
19 | ** File : timer.c
20 | ** Author : Sriharsha
21 | ** Website : www.zuna.in
22 | ** Email : helpzuna@gmail.com
23 | ** Description: This is the hardware timer driver for 8051 family MCU's
24 | ***/
25 |
26 | #include "timer.h"
27 |
28 |
29 | #ifdef ENABLE_TIMER_0_INTERRUPT
30 | volatile unsigned int TimerCount0 = 0;
31 | #endif
32 |
33 |
34 | /*** Function : timerBegin
35 | ** Parameters : unsigned char,unsigned char -> Timer Number, Timer Value (In milliseconds),unsigned long -> Oscillator Frequency in Hz
36 | ** Return : None
37 | ** Description : It will initiates the timer
38 | **/
39 | void timerBegin(unsigned char TimerNo,unsigned char TimerVal,unsigned long oscFreq)
40 | {
41 | int reloadVal = 0;
42 | // Set Timer Mode
43 | TMOD |= 0x01;
44 |
45 | reloadVal = _timer_0_1_mode_2_calc(TimerVal,oscFreq);
46 | TL0 = reloadVal >> 8;
47 | TH0 = reloadVal;
48 | }
49 |
50 | /*** Function : timerStart
51 | ** Parameters : unsigned char,unsigned char -> Timer Number, Interrupts (0-> Disabled,1->Enabled)
52 | ** Return : None
53 | ** Description : It will Start The Timer
54 | **/
55 | void timerStart(unsigned char TimerNo,unsigned char _inter)
56 | {
57 | if(TimerNo == TIMER0)
58 | {
59 | if(_inter == 1)
60 | {
61 | IE_1 = 1;
62 | EA = 1
63 | }
64 | TR0 = 1;
65 | }
66 | else if(TimerNo == TIMER1)
67 | {
68 | if(_inter == 1)
69 | {
70 | IE_3 = 1;
71 | EA = 1
72 | }
73 | TR1 = 1;
74 | }
75 | }
76 |
77 | /*** Function : timerStop
78 | ** Parameters : unsigned char (Timer Number)
79 | ** Return : None
80 | ** Description : It will Stop The Timer
81 | **/
82 | void timerStop(unsigned char TimerNo)
83 | {
84 | if(TimerNo == TIMER0)
85 | {
86 | TR0 = 0;
87 | IE_1 = 0;
88 | }
89 | else if(TimerNo == TIMER1)
90 | {
91 | TR1 = 0;
92 | IE_3 = 0;
93 | }
94 | }
95 |
96 |
97 | /*** Function : N/A (It's an ISR)
98 | ** Parameters : None
99 | ** Return : None
100 | ** Description : This is ISR for TIMER - 0 of 8051
101 | **/
102 | #ifdef ENABLE_TIMER_0_INTERRUPT
103 | #if TOOLCHAIN == SDCC
104 | void timer0ISR(void) __interrupt(1)
105 | {
106 | TimerCount0++;
107 | TF0 = 0;
108 | }
109 | #elif TOOLCHAIN == KEIL
110 | void timer0ISR(void) interrupt(1)
111 | {
112 | TimerCount0++;
113 | TF0 = 0;
114 | }
115 | #error "Invalid Toolchain, Please check 'TOOLCHAIN' macro (SDCC/KEIL)"
116 | #endif
117 |
118 | /*** Function : timerClear0
119 | ** Parameters : None
120 | ** Return : None
121 | ** Description : This function clears the count of TIMER - 0
122 | **/
123 | void timerClear0(void)
124 | {
125 | TimerCount0 = 0;
126 | }
127 |
128 | #endif
--------------------------------------------------------------------------------
/I2C/i2c.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 |
20 | /***
21 | ** File : i2c.h
22 | ** Author : Sriharsha
23 | ** Website : www.zuna.in
24 | ** Email : helpzuna@gmail.com
25 | ** Description: This is the i2c include file for 8051 family MCU's
26 | ***/
27 | #ifndef __i2c_h__
28 | #define __i2c_h__
29 |
30 |
31 | #ifndef SDCC
32 | #define SDCC 0
33 | #endif
34 | #ifndef KEIL
35 | #define KEIL 1
36 | #endif
37 |
38 | #ifndef TOOLCHAIN
39 | #define TOOLCHAIN SDCC
40 | #endif
41 |
42 | #if TOOLCHAIN == SDCC
43 | #include <8051.h> // 8051 Peripheral Address preprocessor file
44 | #elif TOOLCHAIN == KEIL
45 | #include
46 | #else
47 | #error "Invalid Toolchain, Please check 'TOOLCHAIN' macro (SDCC/KEIL)"
48 | #endif
49 |
50 | // Port Definitions
51 | #define SDADIR P0 // SDA Direction Register
52 | #define SCLDIR P0 // SCL Direction Register
53 |
54 | #define SDAPORT P0 // SDA Output Register
55 | #define SCLPORT P0 // SCL Output Register
56 |
57 | #define SDAPIN P0 // SDA Input Register
58 | #define SCLPIN P0 // SCL Input Register
59 |
60 | #define SDABIT 1 << 0 // SDA Bit Position
61 | #define SCLBIT 1 << 1 // SCL Bit Position
62 |
63 | #define SDA ( (SDAPIN ) & (SDABIT) ) // SDA
64 | #define SCL ( (SCLPIN ) & (SCLBIT) ) // SCL
65 |
66 |
67 | #define SDA_HIGH SDAPORT |= SDABIT
68 | #define SDA_LOW SDAPORT &= ~SDABIT
69 |
70 | #define SCL_HIGH SCLPORT |= SCLBIT
71 | #define SCL_LOW SCLPORT &= ~SCLBIT
72 |
73 | #define I2C_CLOCK_VAR 100
74 | #define I2C_SCAN_TIMEOUT_COUNTER_VAL 50000
75 |
76 | #define i2cClock(val) i2cDelay(val)
77 |
78 | #define CLOCK_ERROR_CORRECTION 3
79 |
80 | /***************** Prototypes ******************************/
81 | extern unsigned char i2cBegin(unsigned long,unsigned long); // Osc Freq, Speed
82 | extern unsigned char i2cDetect(unsigned char); // Device Address
83 | extern unsigned char i2cavailable(void);
84 |
85 | extern void i2cStart(void);
86 | extern void i2cStop(void);
87 |
88 | extern void i2cWritebyte(unsigned char);
89 | extern unsigned char i2cReadbyte(unsigned char);
90 |
91 | extern void i2cWrite(unsigned char,unsigned char);
92 | extern unsigned char i2cRead(unsigned char);
93 |
94 | extern void i2cWriteBlock(unsigned char,unsigned char,unsigned char*);
95 | extern void i2cReadBlock(unsigned char,unsigned char,unsigned char*);
96 |
97 | extern void i2csetAdd(unsigned char);
98 | extern unsigned char* i2cScan(unsigned char ,unsigned char);
99 | /***********************************************************/
100 |
101 | #endif
102 |
--------------------------------------------------------------------------------
/ADC0804/adc0804.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 |
20 | /***
21 | ** File : adc0804.h
22 | ** Author : Sriharsha
23 | ** Website : www.zuna.in
24 | ** Email : helpzuna@gmail.com
25 | ** Description: This is the ADC0804 include file for 8051 family MCU's
26 | ***/
27 |
28 | #ifndef __adc0804_h__
29 | #define __adc0804_h__
30 |
31 | //#define ADC_0804_EOC_CONNECT_INTERRUPT
32 | //#define ADC_0804_CS_ENABLED
33 | #define ADC0804_RESOLUTION 8
34 |
35 | // Pin Definitions
36 | #if ADC0804_RESOLUTION >= 1
37 | #define ADC0804_D0_DIR P1
38 | #define ADC0804_D0_OUT P1
39 | #define ADC0704_D0_IN P1
40 | #define ADC0804_D0_BIT 1 << 0
41 |
42 | #elif ADC0804_RESOLUTION >= 2
43 | #define ADC0804_D1_DIR P1
44 | #define ADC0804_D1_OUT P1
45 | #define ADC0704_D1_IN P1
46 | #define ADC0804_D1_BIT 1 << 1
47 |
48 | #elif ADC0804_RESOLUTION >= 3
49 | #define ADC0804_D2_DIR P1
50 | #define ADC0804_D2_OUT P1
51 | #define ADC0704_D2_IN P1
52 | #define ADC0804_D2_BIT 1 <<
53 |
54 | #elif ADC0804_RESOLUTION >= 4
55 | #define ADC0804_D3_DIR P1
56 | #define ADC0804_D3_OUT P1
57 | #define ADC0704_D3_IN P1
58 | #define ADC0804_D3_BIT 1 << 3
59 |
60 | #elif ADC0804_RESOLUTION >= 5
61 | #define ADC0804_D4_DIR P1
62 | #define ADC0804_D4_OUT P1
63 | #define ADC0704_D4_IN P1
64 | #define ADC0804_D4_BIT 1 << 4
65 |
66 | #elif ADC0804_RESOLUTION >= 6
67 | #define ADC0804_D5_DIR P1
68 | #define ADC0804_D5_OUT P1
69 | #define ADC0704_D5_IN P1
70 | #define ADC0804_D5_BIT 1 << 5
71 |
72 | #elif ADC0804_RESOLUTION >= 7
73 | #define ADC0804_D6_DIR P1
74 | #define ADC0804_D6_OUT P1
75 | #define ADC0704_D6_IN P1
76 | #define ADC0804_D6_BIT 1 << 6
77 |
78 | #elif ADC0804_RESOLUTION >= 8
79 | #define ADC0804_D7_DIR P1
80 | #define ADC0804_D7_OUT P1
81 | #define ADC0704_D7_IN P1
82 | #define ADC0804_D7_BIT 1 << 7
83 |
84 | #endif
85 |
86 | #define ADC0804_RD_DIR P2
87 | #define ADC0804_RD_OUT P2
88 | #define ADC0804_RD_IN P2
89 | #define ADC0804_RD_BIT 1 << 0
90 |
91 | #define ADC0804_WR_DIR P2
92 | #define ADC0804_WR_OUT P2
93 | #define ADC0804_WR_IN P2
94 | #define ADC0804_WR_BIT 1 << 1
95 |
96 | #ifdef ADC_0804_CS_ENABLED
97 |
98 | #define ADC0804_CS_ACTIVE_LOW
99 | //#define ADC0804_CS_ACTIVE_HIGH
100 |
101 | #define ADC0804_CS_DIR P2
102 | #define ADC0804_CS_OUT P2
103 | #define ADC0804_CS_IN P2
104 | #define ADC0804_CS_BIT 1 << 2
105 |
106 | #ifdef ADC0804_CS_ACTIVE_LOW
107 | #define ADC0804_EN_CS ADC0804_CS_OUT &= (~ADC0804_CS_BIT)
108 | #define ADC0804_DIS_CS ADC0804_CS_OUT |= ( ADC0804_CS_BIT0)
109 | #endif
110 |
111 | #ifdef ADC0804_CS_ACTIVE_HIGH
112 | #define ADC0804_EN_CS ADC0804_CS_OUT |= ( ADC0804_CS_BIT0)
113 | #define ADC0804_DIS_CS ADC0804_CS_OUT &= (~ADC0804_CS_BIT)
114 | #endif
115 |
116 | #endif
117 |
118 | #ifndef ADC_0804_EOC_CONNECT_INTERRUPT
119 |
120 | #define ADC0804_EOC_DIR P2
121 | #define ADC0804_EOC_OUT P2
122 | #define ADC0804_EOC_IN P2
123 | #define ADC0804_EOC_BIT 1 << 2
124 |
125 | #else
126 | #define ADC0804_EOC_DIR P3
127 | #define ADC0804_EOC_OUT P3
128 | #define ADC0804_EOC_IN P3
129 | #define ADC0804_EOC_BIT 1 << 2
130 |
131 | #endif
132 |
133 | #define ADC0804_TIMEOUT_COUNTER_VAL 100
134 |
135 | #define ADC0804_DELAY_MS 1
136 |
137 | #define adc0804_delay_var 1275
138 |
139 | #define __adc0804__delay__(val) _adc_0804_delay_loop(val)
140 |
141 | extern void _adc_0804_delay_loop(signed int);
142 | extern void adc0804Begin(void);
143 | extern void adc0804initPorts(void);
144 | extern unsigned char adc0804start(void);
145 | extern unsigned char adc0804Read(void);
146 | //extern void adc0804setInterrupt(unsigned char);
147 |
148 | #endif
149 |
--------------------------------------------------------------------------------
/ADC0804/adc0804.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 |
20 | /***
21 | ** File : adc0804.c
22 | ** Author : Sriharsha
23 | ** Website : www.zuna.in
24 | ** Email : helpzuna@gmail.com
25 | ** Description: This is the ADC0804 driver for 8051 family MCU's
26 | ***/
27 |
28 | #include "adc0804.h"
29 |
30 | /*** Function : _adc_0804_delay_loop
31 | ** Parameters : None
32 | ** Return : None
33 | ** Description : It's delay loop for ADC0804
34 | **/
35 | void _adc_0804_delay_loop(signed int __msec)
36 | {
37 | signed int teMp;
38 | for(;msec;msec--)
39 | for(teMp = adc0804_delay_var;teMp;temP--);
40 | }
41 |
42 | /*** Function : adc0804setPorts
43 | ** Parameters : None
44 | ** Return : None
45 | ** Description : It will set the ADC0804 Port
46 | **/
47 | void adc0804initPorts(void)
48 | {
49 | #if ADC0804_RESOLUTION >= 1
50 | ADC0804_D0_DIR |= ADC0804_D0_BIT;
51 | ADC0804_D0_OUT |= ADC0804_D0_BIT;
52 | #elif ADC0804_RESOLUTION >= 2
53 | ADC0804_D1_DIR |= ADC0804_D1_BIT;
54 | ADC0804_D1_OUT |= ADC0804_D1_BIT;
55 | #elif ADC0804_RESOLUTION >= 3
56 | ADC0804_D2_DIR |= ADC0804_D2_BIT;
57 | ADC0804_D2_OUT |= ADC0804_D2_BIT;
58 | #elif ADC0804_RESOLUTION >= 4
59 | ADC0804_D3_DIR |= ADC0804_D3_BIT;
60 | ADC0804_D3_OUT |= ADC0804_D3_BIT;
61 | #elif ADC0804_RESOLUTION >= 5
62 | ADC0804_D4_DIR |= ADC0804_D4_BIT;
63 | ADC0804_D4_OUT |= ADC0804_D4_BIT;
64 | #elif ADC0804_RESOLUTION >= 6
65 | ADC0804_D5_DIR |= ADC0804_D5_BIT;
66 | ADC0804_D5_OUT |= ADC0804_D5_BIT;
67 | #elif ADC0804_RESOLUTION >= 7
68 | ADC0804_D6_DIR |= ADC0804_D6_BIT;
69 | ADC0804_D6_OUT |= ADC0804_D6_BIT;
70 | #elif ADC0804_RESOLUTION >= 8
71 | ADC0804_D3_DIR |= ADC0804_D3_BIT;
72 | ADC0804_D3_OUT |= ADC0804_D3_BIT;
73 | #endif
74 |
75 | // Read Data
76 | ADC0804_RD_DIR |= ADC0804_RD_BIT;
77 | ADC0804_RD_OUT |= ADC0804_RD_BIT;
78 |
79 | // Write Strobe
80 | ADC0804_WR_DIR |= ADC0804_WR_BIT;
81 | ADC0804_WR_OUT |= ADC0804_WR_BIT;
82 |
83 | // End Of Conversion
84 | ADC0804_EOC_DIR |= ADC0804_EOC_BIT;
85 | ADC0804_EOC_OUT |= ADC0804_EOC_BIT;
86 |
87 | #ifdef ADC_0804_CS_ENABLED
88 | ADC0804_CS_DIR |= ADC0804_CS_BIT;
89 | ADC0804_CS_OUT |= ADC0804_CS_BIT;
90 | #endif
91 | }
92 |
93 | /*** Function : adc0804Begin
94 | ** Parameters : None
95 | ** Return : None
96 | ** Description : It will initiate the ADC0804
97 | **/
98 | void adc0804Begin(void)
99 | {
100 | adc0804initPorts();
101 | }
102 |
103 |
104 | /*** Function : adc0804start
105 | ** Parameters : None
106 | ** Return : None
107 | ** Description : It will start the conversion
108 | **/
109 | unsigned char adc0804start(void)
110 | {
111 | unsigned int i = 0;
112 | #ifdef ADC_0804_CS_ENABLED
113 | ADC0804_EN_CS;
114 | #endif
115 | ADC0804_WR_OUT &= (~ADC0804_WR_BIT);
116 | #ifdef ADC_0804_CS_ENABLED
117 | ADC0804_DIS_CS;
118 | #endif
119 |
120 | ADC0804_WR_OUT |= ADC0804_WR_BIT;
121 |
122 | #ifdef ADC_0804_CS_ENABLED
123 | ADC0804_EN_CS;
124 | #endif
125 |
126 | while( (i < ADC0804_TIMEOUT_COUNTER_VAL) && ((ADC0804_EOC_IN & 0x00) & ADC0804_EOC_BIT))
127 | {
128 | i++;
129 | }
130 | if(i > ADC0804_TIMEOUT_COUNTER_VAL)
131 | return 0;
132 | else
133 | return 1;
134 | }
135 |
136 | /*** Function : adc0804Begin
137 | ** Parameters : None
138 | ** Return : None
139 | ** Description : It will start the conversion
140 | **/
141 | unsigned char adc0804Read(void)
142 | {
143 | unsigned int i = 0;
144 | unsigned char readVal = 0x00;
145 | if(adc0804start == 1)
146 | {
147 | #ifdef ADC_0804_CS_ENABLED
148 | ADC0804_EN_CS;
149 | #endif
150 | ADC0804_RD_OUT &= (~ADC0804_RD_BIT);
151 | #ifdef ADC_0804_CS_ENABLED
152 | ADC0804_DIS_CS;
153 | #endif
154 |
155 | #if ADC0804_RESOLUTION >= 1
156 | readVal |= (ADC0804_D0_IN & 0x00) & ADC0804_D0_BIT;
157 | #elif ADC0804_RESOLUTION >= 2
158 | readVal |= (ADC0804_D1_IN & 0x00) & ADC0804_D1_BIT;
159 | #elif ADC0804_RESOLUTION >= 3
160 | readVal |= (ADC0804_D2_IN & 0x00) & ADC0804_D2_BIT;
161 | #elif ADC0804_RESOLUTION >= 4
162 | readVal |= (ADC0804_D3_IN & 0x00) & ADC0804_D3_BIT;
163 | #elif ADC0804_RESOLUTION >= 5
164 | readVal |= (ADC0804_D4_IN & 0x00) & ADC0804_D4_BIT;
165 | #elif ADC0804_RESOLUTION >= 6
166 | readVal |= (ADC0804_D5_IN & 0x00) & ADC0804_D5_BIT;
167 | #elif ADC0804_RESOLUTION >= 7
168 | readVal |= (ADC0804_D6_IN & 0x00) & ADC0804_D6_BIT;
169 | #elif ADC0804_RESOLUTION >= 8
170 | readVal |= (ADC0804_D7_IN & 0x00) & ADC0804_D7_BIT;
171 | #endif
172 |
173 | ADC0804_RD_OUT |= ADC0804_RD_BIT;
174 | #ifdef ADC_0804_CS_ENABLED
175 | ADC0804_EN_CS;
176 | #endif
177 | return readVal;
178 | }
179 | else
180 | {
181 | return 0;
182 | }
183 | }
184 |
185 |
186 |
--------------------------------------------------------------------------------
/LCD/lcd.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 | /***
20 | ** File : lcd.h
21 | ** Author : Sriharsha
22 | ** Website : www.zuna.in
23 | ** Email : helpzuna@gmail.com
24 | ** Description: This is include file for LCD library for 8051 family MCU's
25 | ***/
26 | #ifndef __lcd_h__
27 | #define __lcd_h__
28 |
29 | #ifndef SDCC
30 | #define SDCC 0
31 | #endif
32 | #ifndef KEIL
33 | #define KEIL 1
34 | #endif
35 |
36 | #ifndef TOOLCHAIN
37 | #define TOOLCHAIN SDCC
38 | #endif
39 |
40 | #if TOOLCHAIN == SDCC
41 | #include <8051.h> // 8051 Peripheral Address preprocessor file
42 | #elif TOOLCHAIN == KEIL
43 | #include
44 | #else
45 | #error "Invalid Toolchain, Please check 'TOOLCHAIN' macro (SDCC/KEIL)"
46 | #endif
47 |
48 | #include
49 |
50 | // If you are using R/W Pin
51 | //#define LCD_RW_ENABLED 1
52 |
53 | // LCD Type (16x2,20x4)
54 | #define _LCD_TYPE_ 1 // 1 -> 20x2 , 2-> 16x2
55 | #define LCD_MODE 2 // 1-> 8-bit Mode,2-> 4-Bit Mode
56 |
57 | // LCD Pin definitions
58 | // RS of LCD Direction,OUTPUT and Bit Position
59 | #define LCD_RS_PORT P1
60 | #define LCD_RS_DIR P1
61 | #define LCD_RS_BIT 1 << 5
62 |
63 | // EN of LCD Direction,OUTPUT and Bit Position
64 | #define LCD_EN_PORT P1
65 | #define LCD_EN_DIR P1
66 | #define LCD_EN_BIT 1 << 4
67 |
68 | #ifdef LCD_RW_ENABLED
69 | // RW of LCD Direction,OUTPUT and Bit Position
70 | #define LCD_RW_PORT P1
71 | #define LCD_RW_DIR P1
72 | #define LCD_RW_BIT 1 << 6
73 | #endif
74 |
75 | // If 8-bit mode
76 | #if LCD_MODE == 1
77 | // D0 of LCD Direction,OUTPUT and Bit Position
78 | #define LCD_D0_PORT P1
79 | #define LCD_D0_DIR P1
80 | #define LCD_D0_BIT 1 << 0
81 |
82 | // D1 of LCD Direction,OUTPUT and Bit Position
83 | #define LCD_D1_PORT P1
84 | #define LCD_D1_DIR P1
85 | #define LCD_D1_BIT 1 << 1
86 |
87 | // D2 of LCD Direction,OUTPUT and Bit Position
88 | #define LCD_D2_PORT P1
89 | #define LCD_D2_DIR P1
90 | #define LCD_D2_BIT 1 << 2
91 |
92 | // D3 of LCD Direction,OUTPUT and Bit Position
93 | #define LCD_D3_PORT P1
94 | #define LCD_D3_DIR P1
95 | #define LCD_D3_BIT 1 << 3
96 | #endif
97 |
98 | // Default Mode 4 - Bit (It also includes 8-bit pin definitions)
99 | // D4 of LCD Direction,OUTPUT and Bit Position
100 | #define LCD_D4_PORT P1
101 | #define LCD_D4_DIR P1
102 | #define LCD_D4_BIT 1 << 0
103 |
104 | // D5 of LCD Direction,OUTPUT and Bit Position
105 | #define LCD_D5_PORT P1
106 | #define LCD_D5_DIR P1
107 | #define LCD_D5_BIT 1 << 1
108 |
109 | // D6 of LCD Direction,OUTPUT and Bit Position
110 | #define LCD_D6_PORT P1
111 | #define LCD_D6_DIR P1
112 | #define LCD_D6_BIT 1 << 2
113 |
114 | // D7 of LCD Direction,OUTPUT and Bit Position
115 | #define LCD_D7_PORT P1
116 | #define LCD_D7_DIR P1
117 | #define LCD_D7_BIT 1 << 3
118 |
119 | // RS(Register Select) LOW and HIGH macros
120 | #define LCD_COMMAND_MODE_RS LCD_RS_PORT &= ~LCD_RS_BIT
121 | #define LCD_DATA_MODE_RS LCD_RS_PORT |= LCD_RS_BIT
122 |
123 | // Enable LOW and HIGH macros
124 | #define LCD_ENABLE_LOW LCD_EN_PORT &= ~LCD_EN_BIT
125 | #define LCD_ENABLE_HIGH LCD_EN_PORT |= LCD_EN_BIT
126 |
127 | // LCD standard commands
128 | #define LCD_4BIT_1_LINE_5_x_7 0x20
129 | #define LCD_4BIT_2_LINE_5_x_7 0x28
130 | #define LCD_8BIT_1_LINE_5_x_7 0x30
131 | #define LCD_8BIT_2_LINE_5_x_7 0x38
132 | #define LCD_ENTRY_MODE 0x06
133 | #define LCD_DISPLAY_OFF_CURSOR_OFF 0x08
134 | #define LCD_DISPLAY_ON_CURSOR_ON 0x0E
135 | #define LCD_DISPLAY_ON_CURSOR_OFF 0x0C
136 | #define LCD_DISPLAY_ON_CURSOR_BLINKING 0x0F
137 | #define LCD_DISPLAY_SHIFT_ENTIRE_LEFT 0x18
138 | #define LCD_DISPLAY_SHIFT_ENTIRE_RIGHT 0x1C
139 | #define LCD_MOVE_CURSOR_LEFT_ONE_CHAR 0x10
140 | #define LCD_MOVE_CURSOR_RIGHT_ONE_CHAR 0x14
141 | #define LCD_CLEAR_ALSO_DDRAM 0x01
142 |
143 | // LCD Row Addresses
144 | #define LCD_ADDRESS_ROW1 0x80
145 | #define LCD_ADDRESS_ROW2 0xC0
146 | #define LCD_ADDRESS_ROW3 0x94
147 | #define LCD_ADDRESS_ROW4 0xD4
148 |
149 | // Delay macros
150 | #define __delay_ms__(x) __delay_loop_((long) x*50)
151 | #define __delay_us__(x) __delay_loop_((long) x)
152 |
153 | // Prototype Declaration
154 | extern void lcdWrite(unsigned char);
155 | extern void lcdPrint(unsigned char *);
156 | extern void lcdBegin(void);
157 | extern void lcdSetCursor(int,int);
158 | extern void lcdClear(void);
159 | extern void lcdWriteint(signed int);
160 |
161 | extern void lcd_command(unsigned char);
162 | extern void lcd_data(unsigned char);
163 | extern void lcdEnable(void);
164 | extern void lcd_port_init(void);
165 | extern void lcdwrite4Bits(unsigned char);
166 | extern void lcdwrite8Bits(unsigned char);
167 | extern void lcdSendbyte(unsigned char);
168 |
169 | extern void __delay_loop_(signed long);
170 |
171 | #endif
172 |
--------------------------------------------------------------------------------
/UART/uart.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 | /***
19 | ** File : uart.h
20 | ** Author : Sriharsha
21 | ** Website : www.zuna.in
22 | ** Email : helpzuna@gmail.com
23 | ** Description: This is the include file for 8051 uart driver
24 | ***/
25 |
26 | #ifndef __uart_h__
27 | #define __uart_h__
28 |
29 | // UART Clock Source
30 | #define __TIMER_1__ 0
31 | #define __TIMER_2__ 1
32 |
33 | #define UART_CLOCK_SOURCE __TIMER_2__
34 |
35 |
36 | #ifndef SDCC
37 | #define SDCC 0
38 | #endif
39 | #ifndef KEIL
40 | #define KEIL 1
41 | #endif
42 |
43 | #ifndef TOOLCHAIN
44 | #define TOOLCHAIN SDCC
45 | #endif
46 |
47 | // If Toolchain is SDCC
48 | #if TOOLCHAIN == SDCC
49 | #if UART_CLOCK_SOURCE == __TIMER_1__
50 | #include <8051.h>
51 | #elif UART_CLOCK_SOURCE == __TIMER_2__
52 | #include <8052.h>
53 | #endif
54 |
55 | // If Toolchain is Keil
56 | #elif TOOLCHAIN == KEIL
57 | #if UART_CLOCK_SOURCE == __TIMER_1__
58 | #include
59 | #elif UART_CLOCK_SOURCE == __TIMER_2__
60 | #include
61 | #endif
62 |
63 | // If invalid raise an error
64 | #else
65 | #error "Invalid Toolchain, Please check 'TOOLCHAIN' macro (SDCC/KEIL)"
66 | #endif
67 | #include // Standard input/output file used in Serialintwrite (sprintf)
68 |
69 | // Serial Interrupt Enable
70 | #define SERIAL_RX_INTERRUPT_ENABLE
71 |
72 | // UART Buffer Size
73 | #define UART_RX_BUFFER_SIZE 20
74 |
75 | // New Line Index Buffer Size
76 | #define NEW_LINE_INDEX_BUFFER_SIZE 10
77 |
78 | // BaudRate Calculation
79 | #define __baudRate_calc_timer_1(__freq,__baud) (256 - ((__freq/384) / __baud))
80 | #define __baudRate_calc_timer_2(__freq,__baud) (65536 - (__freq/(__baud*32)))
81 |
82 | // ASCII Code Definitions
83 | #define NUL 0x00 // Null Character
84 | #define SOH 0x01 // Start Of Heading
85 | #define STX 0x02 // Start Of Text
86 | #define ETX 0x03 // End Of Text
87 | #define EOT 0x04 // End of Transmission
88 | #define ENQ 0x05 // Enquiry
89 | #define ACK 0x06 // Acknowledgement
90 | #define BEL 0x07 // Bell
91 | #define BS 0x08 // Back Space
92 | #define TAB 0x09 // Horizontal TAB
93 | #define LF 0x0A // Line Feed (Newline)
94 | #define VT 0x0B // Vertical TAB
95 | #define NP 0x0C // New Page
96 | #define CR 0x0D // Carriage Return
97 | #define SO 0x0E // Shift OUT
98 | #define SI 0x0F // Shift IN
99 | #define DLE 0x10 // Data Link Escape
100 | #define DC1 0x11 // Device Control 1
101 | #define DC2 0x12 // Device Control 2
102 | #define DC3 0x13 // Device Control 3
103 | #define DC4 0x14 // Device Control 4
104 | #define NAK 0x15 // Negative Acknowledgement
105 | #define SYN 0x16 // Synchronous Idle
106 | #define ETB 0x17 // End of Trans. Block
107 | #define CAN 0x18 // Cancel
108 | #define EM 0x19 // End of Medium
109 | #define SUB 0x1A // Substitute
110 | #define ESC 0x1B // Escape
111 | #define FS 0x1C // File Seperator
112 | #define GS 0x1D // Group Seperator
113 | #define RS 0x1E // Record Seperator
114 | #define US 0x1F // Unit Seperator
115 |
116 | #define CHAR_NULL '\0'
117 |
118 | /***************** Prototypes ****************************/
119 | extern void Serialbegin(unsigned long,unsigned long);
120 | extern unsigned char Serialavailable(void);
121 | extern void Serialwrite(unsigned char);
122 | extern void Serialprint(unsigned char *);
123 | extern unsigned char Serialread(void);
124 | extern void SerialIntWrite(signed int);
125 | extern void SetOsc(unsigned long);
126 |
127 |
128 | #ifdef SERIAL_RX_INTERRUPT_ENABLE
129 |
130 | #if TOOLCHAIN == SDCC
131 | extern void uartISR(void) __interrupt (4);
132 | #elif TOOLCHAIN == KEIL
133 | extern void uartISR(void) interrupt (4);
134 | #else
135 | #error "Invalid Toolchain, Please check 'TOOLCHAIN' macro (SDCC/KEIL)"
136 | #endif
137 |
138 | extern void setSerialinterrupt(void);
139 | extern void Serialflush(void);
140 |
141 |
142 | extern volatile unsigned char uartNewLineFlag;
143 | extern volatile unsigned char uartReadByte;
144 | extern volatile unsigned char uartReadBuffer[UART_RX_BUFFER_SIZE];
145 | extern volatile unsigned int uartReadCount;
146 | extern volatile unsigned char uartNewLineCount;
147 | extern volatile unsigned char uartNewLineIndexes[NEW_LINE_INDEX_BUFFER_SIZE];
148 | #endif
149 |
150 | #endif
151 |
152 |
--------------------------------------------------------------------------------
/UART/uart.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 | /***
19 | ** File : uart.c
20 | ** Author : Sriharsha
21 | ** Website : www.zuna.in
22 | ** Email : helpzuna@gmail.com
23 | ** Description: This is the uart driver for 8051 family MCU's
24 | ***/
25 |
26 | #include "uart.h"
27 |
28 | // Globals
29 |
30 |
31 | #ifdef SERIAL_RX_INTERRUPT_ENABLE
32 |
33 | // Uart New Line Flag (Set when new line received)
34 | volatile unsigned char uartNewLineFlag = 0;
35 | // UART Read Buffer to store Received Data
36 | volatile unsigned char uartReadBuffer[UART_RX_BUFFER_SIZE];
37 | // Uart Byte Count
38 | volatile unsigned int uartReadCount = 0;
39 | // Uart New Line Count
40 | volatile unsigned char uartNewLineCount = 0;
41 | // It holds every new line index
42 | volatile unsigned char uartNewLineIndexes[NEW_LINE_INDEX_BUFFER_SIZE];
43 | // It hold single byte (Last Received)
44 | volatile unsigned char uartReadByte = CHAR_NULL;
45 |
46 | #endif
47 |
48 |
49 |
50 |
51 | /*** Function : Serialbegin
52 | ** Parameters : unsigned long (OscillatorFrequency),unsigned long (Standard BaudRate)
53 | ** Parameters : unsigned long (OscillatorFrequency),unsigned long (Standard BaudRate)
54 | ** Return : None
55 | ** Description : It will Set the baud rate for serial communication
56 | **/
57 | void Serialbegin(unsigned long OscillatorFrequency,unsigned long baudRate)
58 | {
59 | volatile unsigned int autoReloadvalue;
60 | #if UART_CLOCK_SOURCE == __TIMER_1__
61 | autoReloadvalue = __baudRate_calc_timer_1(OscillatorFrequency,baudRate);
62 | TMOD |= 0x20;
63 | SCON |= 0x50;
64 | TL1 = autoReloadvalue >> 8;
65 | TH1 = autoReloadvalue;
66 | TR1 = 1
67 | #elif UART_CLOCK_SOURCE == __TIMER_2__
68 | autoReloadvalue= __baudRate_calc_timer_2(OscillatorFrequency,baudRate);
69 | T2CON = 0x00;
70 | T2CON = 0x30;
71 | SCON = 0x50;
72 | RCAP2H = autoReloadvalue >> 8;
73 | RCAP2L = autoReloadvalue;
74 | TH2 = autoReloadvalue >> 8;
75 | TL2 = autoReloadvalue;
76 | TR2 = 1;
77 | #endif
78 | }
79 |
80 | /*** Function : Serialavailable
81 | ** Parameters : None
82 | ** Return : __bit (If byte is available in receive buffer returns 1, else returns 0)
83 | ** Description : It will give the whether Receiver is available or not
84 | **/
85 | unsigned char Serialavailable(void)
86 | {
87 | return RI;
88 | }
89 |
90 |
91 | /*** Function : Serialwrite
92 | ** Parameters : unsigned char (Single character that will send to UART)
93 | ** Return : None
94 | ** Description : It will write single character to UART
95 | **/
96 | void Serialwrite(unsigned char Byte)
97 | {
98 | #ifdef SERIAL_RX_INTERRUPT_ENABLE
99 | EA = 0;
100 | #endif
101 | SBUF = Byte;
102 | while(!TI);
103 | TI = 0;
104 | #ifdef SERIAL_RX_INTERRUPT_ENABLE
105 | EA = 1;
106 | #endif
107 | }
108 |
109 | /*** Function : Serialread
110 | ** Parameters : None
111 | ** Return : unsigned char
112 | ** Description : It will read single byte from uart
113 | **/
114 | unsigned char Serialread(void)
115 | {
116 | while(!RI);
117 | return SBUF;
118 | }
119 |
120 | /*** Function : Serialprint
121 | ** Parameters : unsigned char *
122 | ** Return : None
123 | ** Description : It will send the string to UART
124 | **/
125 | void Serialprint(unsigned char *sPtr)
126 | {
127 | for(;*sPtr!='\0';Serialwrite(*(sPtr++)));
128 | }
129 |
130 |
131 | /*** Function : Serialprint
132 | ** Parameters : unsigned char *
133 | ** Return : None
134 | ** Description : It will send the string to UART
135 | **/
136 | void SerialIntWrite(signed int num)
137 | {
138 | char *tempBuffer;
139 | sprintf(tempBuffer,"%d",num);
140 | Serialprint((unsigned char*)tempBuffer);
141 | }
142 |
143 |
144 | #ifdef SERIAL_RX_INTERRUPT_ENABLE
145 |
146 | /*** Function : setSerialinterrupt
147 | ** Parameters : None
148 | ** Return : None
149 | ** Description : It sets the Serial Interrupt
150 | **/
151 | void setSerialinterrupt(void)
152 | {
153 | ES = 1;
154 | EA = 1;
155 | }
156 |
157 | /*** Function : Serialflush
158 | ** Parameters : None
159 | ** Return : None
160 | ** Description : It clears the UART buffer,Index Buffer and Flags
161 | **/
162 | void Serialflush(void)
163 | {
164 | unsigned char i;
165 | uartReadCount = 0; // Clear Uart Byte Count
166 | uartNewLineFlag = 0; // Clear New Line Flag
167 | uartNewLineCount = 0; // Clear New Line Count
168 | uartReadByte = CHAR_NULL; // Clear Last Read Byte
169 |
170 | // Flush New Line Index Buffer
171 | for(i=0;i<=NEW_LINE_INDEX_BUFFER_SIZE;i++)
172 | uartNewLineIndexes[i] = CHAR_NULL;
173 |
174 | // Flush Uart Read Buffer
175 | for(i=0;i<=UART_RX_BUFFER_SIZE;i++)
176 | uartReadBuffer[i] = CHAR_NULL;
177 | }
178 |
179 | /*** Function : SerialReadByteFlush
180 | ** Parameters : None
181 | ** Return : None
182 | ** Description : It clears the UART Read Byte (uartReadByte)
183 | **/
184 | void SerialReadByteFlush(void)
185 | {
186 | uartReadByte = CHAR_NULL; // Clear Last Read Byte
187 | }
188 |
189 | /*** Function : uartISR
190 | ** Parameters : None
191 | ** Return : None
192 | ** Description : It is ISR for UART Receive (It will trigger if any byte is received)
193 | **/
194 | #if TOOLCHAIN == SDCC
195 | void uartISR(void) __interrupt (4)
196 | {
197 | EA = 0; // Disable Global Interrupt Flag
198 | RI = 0; // Clear RI flag
199 | uartReadByte = SBUF; // Read Byte from SBUF
200 | uartReadBuffer[uartReadCount++] = uartReadByte;
201 | if(uartReadByte == LF)
202 | {
203 | uartNewLineIndexes[uartNewLineCount] = uartReadCount;
204 | uartNewLineCount++;
205 | uartNewLineFlag = 1;
206 | }
207 | EA = 1; // Everything is done , Now Enable the Global Interrupt
208 | }
209 |
210 | #elif TOOLCHAIN == KEIL
211 | void uartISR(void) interrupt (4)
212 | {
213 | EA = 0; // Disable Global Interrupt Flag
214 | RI = 0; // Clear RI flag
215 | uartReadByte = SBUF; // Read Byte from SBUF
216 | uartReadBuffer[uartReadCount++] = uartReadByte;
217 | if(uartReadByte == LF)
218 | {
219 | uartNewLineIndexes[uartNewLineCount] = uartReadCount;
220 | uartNewLineCount++;
221 | uartNewLineFlag = 1;
222 | }
223 | EA = 1; // Everything is done , Now Enable the Global Interrupt
224 | }
225 |
226 | #else
227 | #error "Invalid Toolchain, Please check 'TOOLCHAIN' macro (SDCC/KEIL)"
228 | #endif
229 |
230 | #endif
231 |
232 |
233 |
234 |
--------------------------------------------------------------------------------
/I2C/i2c.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 |
20 | /***
21 | ** File : i2c.c
22 | ** Author : Sriharsha
23 | ** Website : www.zuna.in
24 | ** Email : helpzuna@gmail.com
25 | ** Description: This is the i2c driver for 8051 family MCU's
26 | ***/
27 |
28 | #include "i2c.h"
29 |
30 | unsigned char SlaveACK = 0x00;
31 | unsigned char DevAddress = 0x00;
32 | unsigned char ClockVar = 0x00;
33 |
34 | /*** Function : _time_out_timer_0__
35 | ** Parameters : None
36 | ** Return : None
37 | ** Description : It will give 25ms delay for I2C Detect Timeout
38 | **/
39 | void _time_out_timer_0__(void)
40 | {
41 | TMOD |= 0x01;
42 | TL0 = 0x00;
43 | TH0 = 0x4C;
44 | TR0 = 1;
45 | }
46 |
47 | /*** Function : i2cSetPort
48 | ** Parameters : None
49 | ** Return : None
50 | ** Description : It will set the i2c Port
51 | **/
52 | void i2cSetPort(void)
53 | {
54 | SDADIR |= SDABIT;
55 | SCLDIR |= SCLBIT;
56 | SDA_HIGH;
57 | SCL_HIGH;
58 | }
59 |
60 | /*** Function : i2cDelay
61 | ** Parameters : unsigned int
62 | ** Return : None
63 | ** Description : It's delay loop for i2c Clock Generation
64 | **/
65 | void i2cDelay(unsigned int ClockVar)
66 | {
67 | signed char i;
68 | for(i=0;i<=ClockVar;i++)
69 | {
70 | __asm
71 | NOP
72 | __endasm;
73 | }
74 | }
75 |
76 | /*** Function : i2cavailable
77 | ** Parameters : None
78 | ** Return : unsigned char
79 | ** Description : It will return's the state of i2c bus (Busy -> 0, Free -> 1)
80 | **/
81 | unsigned char i2cavailable(void)
82 | {
83 | return (!(SDA | SCL));
84 | }
85 |
86 | /*** Function : i2cStart
87 | ** Parameters : None
88 | ** Return : None
89 | ** Description : It will Starts the i2c communication
90 | **/
91 | void i2cStart(void)
92 | {
93 | // This Block will execute contiuous until i2c bus become free
94 | back:
95 | if(SDA == 0)
96 | goto back;
97 | if(SCL == 0)
98 | goto back;
99 | // Start communication
100 | SDA_HIGH;
101 | SCL_HIGH;
102 | i2cClock(ClockVar);
103 | SDA_LOW;
104 | SCL_LOW;
105 | }
106 |
107 | /*** Function : i2cStartonce
108 | ** Parameters : None
109 | ** Return : None
110 | ** Description : It will start communication without checking bus state
111 | **/
112 | void i2cStartonce(void)
113 | {
114 | SDA_HIGH;
115 | SCL_HIGH;
116 | i2cClock(ClockVar);
117 | SDA_LOW;
118 | SCL_LOW;
119 | }
120 |
121 | /*** Function : i2cStop
122 | ** Parameters : None
123 | ** Return : None
124 | ** Description : It will stop the i2c communication
125 | **/
126 | void i2cStop(void)
127 | {
128 | SDA_LOW;
129 | SCL_HIGH;
130 | i2cClock(ClockVar);
131 | SDA_HIGH;
132 | SCL_LOW;
133 | }
134 |
135 | /*** Function : i2cWritebyte
136 | ** Parameters : unsigned char (1-Byte value)
137 | ** Return : None
138 | ** Description : It will write single byte to i2c bus
139 | **/
140 | void i2cWritebyte(unsigned char uByte)
141 | {
142 | unsigned char MaskByte;
143 | MaskByte = 0x80;
144 | do
145 | {
146 | if(uByte & MaskByte)
147 | SDA_HIGH;
148 | else
149 | SDA_LOW;
150 | SCL_HIGH;
151 | i2cClock(ClockVar);
152 | SCL_LOW;
153 | i2cClock(ClockVar);
154 | MaskByte /= 2;
155 | }
156 | while(MaskByte>0);
157 | SDA_HIGH;
158 | SCL_HIGH;
159 | i2cClock(ClockVar);
160 | SlaveACK = SDA;
161 | SCL_LOW;
162 | }
163 |
164 | /*** Function : i2cReadbyte
165 | ** Parameters : unsigned char (Master ACK)
166 | ** Return : unsigned char (1-Byte value)
167 | ** Description : It will read single byte from i2c bus
168 | **/
169 | unsigned char i2cReadbyte(unsigned char MasterACK)
170 | {
171 | unsigned char uByte;
172 | unsigned char MaskByte;
173 | uByte = 0;
174 | MaskByte = 0x80;
175 | do
176 | {
177 | SCL_HIGH;
178 | if(SDA == 1)
179 | {
180 | uByte |= MaskByte;
181 | }
182 | SCL_LOW;
183 | MaskByte /= 2;
184 | }
185 | while(MaskByte > 0);
186 | if(MasterACK==1)
187 | SDA_HIGH;
188 | else
189 | SDA_LOW;
190 | SCL_LOW;
191 | SDA_HIGH;
192 | return uByte;
193 | }
194 |
195 | /*** Function : i2cWrite
196 | ** Parameters : unsigned char,unsigned char (Data,Address)
197 | ** Return : unsigned char (1-Byte value)
198 | ** Description : It will write single byte to argued address
199 | **/
200 | void i2cWrite(unsigned char Byte,unsigned char Address)
201 | {
202 | do
203 | {
204 | i2cStart();
205 | i2cWritebyte(DevAddress);
206 | if(SlaveACK == 1)
207 | i2cStop();
208 | }
209 | while(SlaveACK==1);
210 | i2cWritebyte(Address);
211 | i2cWritebyte(Byte);
212 | i2cStop();
213 | }
214 |
215 | /*** Function : i2cRead
216 | ** Parameters : unsigned char (Address)
217 | ** Return : unsigned char (1-Byte value)
218 | ** Description : It will read single byte from argued address
219 | **/
220 | unsigned char i2cRead(unsigned char Address)
221 | {
222 | unsigned char ReadByte;
223 | do
224 | {
225 | i2cStart();
226 | i2cWritebyte(DevAddress);
227 | if(SlaveACK==1)
228 | i2cStop();
229 | }
230 | while(SlaveACK==1);
231 | i2cWritebyte(Address);
232 | i2cStop();
233 | i2cStart();
234 | i2cWritebyte(DevAddress+1);
235 | ReadByte = i2cReadbyte(1);
236 | i2cStop();
237 | return ReadByte;
238 | }
239 |
240 | /*** Function : i2cBegin
241 | ** Parameters : unsigned long (Osc Freq in Hz),unsigned long (Speed in Hz)
242 | ** Return : unsigned char (1-> Device Detected,0->Device Not Detected)
243 | ** Description : It will read initiate the i2c communication
244 | **/
245 | unsigned char i2cBegin(unsigned long OscFreq,unsigned long Speed)
246 | {
247 | unsigned char teMp = 12 / ((OscFreq / 1000)/1000);
248 | teMp = teMp + CLOCK_ERROR_CORRECTION;
249 | ClockVar = teMp / Speed;
250 | }
251 |
252 | /*** Function : i2csetAdd
253 | ** Parameters : unsigned char (Device Address)
254 | ** Return : None
255 | ** Description : It will set the device address for I2C (See global)
256 | **/
257 | void i2csetAdd(unsigned char SlaveAddress)
258 | {
259 | DevAddress = SlaveAddress;
260 | }
261 |
262 | /*** Function : i2cScan
263 | ** Parameters : unsigned char,unsigned char (start Address,End Address)
264 | ** Return : unsigned char* (That contain Address Array and Device Count)
265 | ** Description : It will Scan the i2c devices connected to bus
266 | **/
267 | unsigned char* i2cScan(unsigned char startAddress,unsigned char EndAddress)
268 | {
269 | unsigned char i2cAddressArray[10];
270 | unsigned char DeviceCounter = 0;
271 | unsigned char temp;
272 |
273 | // Clear the buffer
274 | for(temp = 0;temp <= (EndAddress - startAddress);temp++)
275 | i2cAddressArray[temp] = 0;
276 |
277 | // Scan the devices
278 | for(temp = startAddress;temp <= EndAddress;temp++)
279 | {
280 | if(i2cBegin(temp) == 1)
281 | {
282 | DeviceCounter++;
283 | i2cAddressArray[DeviceCounter] = DeviceCounter;
284 | }
285 | }
286 | return i2cAddressArray;
287 | }
288 |
289 | /*** Function : i2cDetect
290 | ** Parameters : unsigned char (Device Address)
291 | ** Return : 1 -> If detected, 0 -> If not detected
292 | ** Description : It will Detect the Slave
293 | **/
294 | unsigned char i2cDetect(unsigned char _Address)
295 | {
296 |
297 | }
298 |
299 | /*** Function : i2cWriteBlock
300 | ** Parameters : unsigned char (Start Address),unsigned char (End Address),unsigned char* (Data)
301 | ** Return : None
302 | ** Description : It will Write block of data into i2c bus
303 | **/
304 | void i2cWriteBlock(unsigned char sAddress,unsigned char eAddress,unsigned char *dPtr)
305 | {
306 | unsigned char duMmy;
307 | unsigned char i = 0;
308 | for(duMmy=sAddress;i<= eAddress;duMmy++)
309 | {
310 | i2cWrite(dPtr[i],duMmy);
311 | i++;
312 | }
313 | }
314 |
315 | /*** Function : i2cReadBlock
316 | ** Parameters : unsigned char (Start Address),unsigned char (End Address),unsigned char* (Data)
317 | ** Return : None
318 | ** Description : It will Read block of data into i2c bus
319 | **/
320 | void i2cReadBlock(unsigned char sAddress,unsigned char eAddress,unsigned char *dPtr)
321 | {
322 | unsigned char duMmy;
323 | unsigned char i = 0;
324 | for(duMmy=sAddress;i<= eAddress;duMmy++)
325 | {
326 | dPtr[i] = i2cRead(duMmy);
327 | i++;
328 | }
329 | }
330 |
331 |
332 |
333 |
334 |
335 |
336 |
--------------------------------------------------------------------------------
/LCD/lcd.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 |
20 | /***
21 | ** File : lcd.c
22 | ** Author : Sriharsha
23 | ** Website : www.zuna.in
24 | ** Email : helpzuna@gmail.com
25 | ** Description: This is the lcd driver for 8051 family MCU's
26 | ***/
27 |
28 | #include "lcd.h"
29 |
30 | /*** Function : __delay_loop_
31 | ** Parameters : signed long
32 | ** Return : None
33 | ** Description : It will give a delay for lcd
34 | **/
35 | void __delay_loop_(signed long val)
36 | {
37 | for(;val;val--);
38 | }
39 |
40 | /*** Function : lcdEnable
41 | ** Parameters : None
42 | ** Return : None
43 | ** Description : It will trigger LCD Enable Signal
44 | **/
45 | void lcdEnable(void)
46 | {
47 | LCD_ENABLE_HIGH;
48 | __delay_us__(1);
49 | LCD_ENABLE_LOW;
50 | }
51 |
52 | /*** Function : lcd_port_init
53 | ** Parameters : None
54 | ** Return : None
55 | ** Description : It will Initiate the I/O Port for LCD
56 | **/
57 | void lcd_port_init(void)
58 | {
59 | // SET RS Port as OUTPUT and Write LOW to PORT
60 | LCD_RS_DIR |= LCD_RS_BIT;
61 | //LCD_RS_PORT &= ~LCD_RS_BIT;
62 | LCD_RS_PORT |= LCD_RS_BIT;
63 | // SET EN Port as OUTPUT and Write LOW to PORT
64 | LCD_EN_DIR |= LCD_EN_BIT;
65 | //LCD_EN_PORT &= ~LCD_EN_BIT;
66 | LCD_EN_PORT |= LCD_EN_BIT;
67 |
68 | // If 8- Bit Mode
69 | #if LCD_MODE == 1
70 | // SET D0 Port as OUTPUT and Write HIGH to PORT
71 | LCD_D0_DIR |= LCD_D0_BIT;
72 | LCD_D0_PORT |= LCD_D0_BIT;
73 | // SET D1 Port as OUTPUT and Write HIGH to PORT
74 | LCD_D1_DIR |= LCD_D1_BIT;
75 | LCD_D1_PORT |= LCD_D1_BIT;
76 | // SET D2 Port as OUTPUT and Write HIGH to PORT
77 | LCD_D2_DIR |= LCD_D2_BIT;
78 | LCD_D2_PORT |= LCD_D2_BIT;
79 | // SET D3 Port as OUTPUT and Write HIGH to PORT
80 | LCD_D3_DIR |= LCD_D3_BIT;
81 | LCD_D3_PORT |= LCD_D3_BIT;
82 | // SET D4 Port as OUTPUT and Write HIGH to PORT
83 | LCD_D4_DIR |= LCD_D4_BIT;
84 | LCD_D4_PORT |= LCD_D4_BIT;
85 | // SET D5 Port as OUTPUT and Write HIGH to PORT
86 | LCD_D5_DIR |= LCD_D5_BIT;
87 | LCD_D5_PORT |= LCD_D5_BIT;
88 | // SET D6 Port as OUTPUT and Write HIGH to PORT
89 | LCD_D6_DIR |= LCD_D6_BIT;
90 | LCD_D6_PORT |= LCD_D6_BIT;
91 | // SET D7 Port as OUTPUT and Write HIGH to PORT
92 | LCD_D7_DIR |= LCD_D7_BIT;
93 | LCD_D7_PORT |= LCD_D7_BIT;
94 | // If 4-Bit Mode
95 | #elif LCD_MODE == 2
96 | // SET D4 Port as OUTPUT and Write HIGH to PORT
97 | LCD_D4_DIR |= LCD_D4_BIT;
98 | LCD_D4_PORT |= LCD_D4_BIT;
99 | // SET D5 Port as OUTPUT and Write HIGH to PORT
100 | LCD_D5_DIR |= LCD_D5_BIT;
101 | LCD_D5_PORT |= LCD_D5_BIT;
102 | // SET D6 Port as OUTPUT and Write HIGH to PORT
103 | LCD_D6_DIR |= LCD_D6_BIT;
104 | LCD_D6_PORT |= LCD_D6_BIT;
105 | // SET D7 Port as OUTPUT and Write HIGH to PORT
106 | LCD_D7_DIR |= LCD_D7_BIT;
107 | LCD_D7_PORT |= LCD_D7_BIT;
108 |
109 | // Else display an error
110 | #else
111 | #error "Invalid LCD TYPE (That should be either '1' or '2')"
112 | #endif
113 | }
114 |
115 | /*** Function : lcdwrite8Bits
116 | ** Parameters : None
117 | ** Return : unsigned char
118 | ** Description : It will write 8-bit to LCD PORT
119 | **/
120 | void lcdwrite8Bits(unsigned char lByte)
121 | {
122 | if(lByte & 0x80)
123 | LCD_D7_PORT |= LCD_D7_BIT;
124 | else
125 | LCD_D7_PORT &= ~LCD_D7_BIT;
126 | if(lByte & 0x40)
127 | LCD_D6_PORT |= LCD_D6_BIT;
128 | else
129 | LCD_D6_PORT &= ~LCD_D6_BIT;
130 | if(lByte & 0x20)
131 | LCD_D5_PORT |= LCD_D5_BIT;
132 | else
133 | LCD_D5_PORT &= ~LCD_D5_BIT;
134 | if(lByte & 0x10)
135 | LCD_D4_PORT |= LCD_D4_BIT;
136 | else
137 | LCD_D4_PORT &= ~LCD_D4_BIT;
138 | #if LCD_MODE == 1
139 | if(lByte & 0x08)
140 | LCD_D3_PORT |= LCD_D3_BIT;
141 | else
142 | LCD_D3_PORT &= ~LCD_D3_BIT;
143 | if(lByte & 0x04)
144 | LCD_D2_PORT |= LCD_D2_BIT;
145 | else
146 | LCD_D2_PORT &= ~LCD_D2_BIT;
147 | if(lByte & 0x02)
148 | LCD_D1_PORT |= LCD_D1_BIT;
149 | else
150 | LCD_D1_PORT &= ~LCD_D1_BIT;
151 | if(lByte & 0x01)
152 | LCD_D0_PORT |= LCD_D0_BIT;
153 | else
154 | LCD_D0_PORT &= ~LCD_D0_BIT;
155 | #endif
156 | lcdEnable();
157 | }
158 |
159 | #define LOWNIB(x) P1OUT = (P1OUT & 0xF0) + (x & 0x0F)
160 |
161 | /*** Function : lcdwrite4Bits
162 | ** Parameters : None
163 | ** Return : unsigned char
164 | ** Description : It will write 4-bit to LCD PORT
165 | **/
166 | void lcdwrite4Bits(unsigned char val)
167 | {
168 | if(val & 0x08)
169 | LCD_D7_PORT |= LCD_D7_BIT;
170 | else
171 | LCD_D7_PORT &= ~LCD_D7_BIT;
172 | if(val & 0x04)
173 | LCD_D6_PORT |= LCD_D6_BIT;
174 | else
175 | LCD_D6_PORT &= ~LCD_D6_BIT;
176 | if(val & 0x02)
177 | LCD_D5_PORT |= LCD_D5_BIT;
178 | else
179 | LCD_D5_PORT &= ~LCD_D5_BIT;
180 | if(val & 0x01)
181 | LCD_D4_PORT |= LCD_D4_BIT;
182 | else
183 | LCD_D4_PORT &= ~LCD_D4_BIT;
184 | lcdEnable();
185 | }
186 |
187 | /*** Function : lcdSendbyte
188 | ** Parameters : None
189 | ** Return : unsigned char
190 | ** Description : It will Send byte to LCD based on 8-bit/4-bit
191 | **/
192 | void lcdSendbyte(unsigned char lByte)
193 | {
194 | #if LCD_MODE == 1
195 | lcdwrite8Bits(lByte);
196 | #elif LCD_MODE == 2
197 | lcdwrite4Bits(lByte >> 4);
198 | lcdwrite4Bits(lByte);
199 | __delay_ms__(5);
200 | #endif
201 | }
202 |
203 | /*** Function : lcd_command
204 | ** Parameters : None
205 | ** Return : unsigned char
206 | ** Description : It will Send byte to lcd as command
207 | **/
208 | void lcd_command(unsigned char lByte)
209 | {
210 | LCD_ENABLE_LOW;
211 | LCD_COMMAND_MODE_RS;
212 | lcdSendbyte(lByte);
213 | }
214 |
215 | /*** Function : lcd_data
216 | ** Parameters : None
217 | ** Return : unsigned char
218 | ** Description : It will Send byte to LCD as data
219 | **/
220 | void lcd_data(unsigned char lByte)
221 | {
222 | LCD_ENABLE_LOW;
223 | LCD_DATA_MODE_RS;
224 | lcdSendbyte(lByte);
225 | }
226 |
227 | /*** Function : lcd_data
228 | ** Parameters : None
229 | ** Return : unsigned char
230 | ** Description : It will send one char to LCD as data
231 | **/
232 | void lcdWrite(unsigned char lByte)
233 | {
234 | lcd_data(lByte);
235 | }
236 |
237 | /*** Function : lcdPrint
238 | ** Parameters : None
239 | ** Return : unsigned char*
240 | ** Description : It will send String to LCD
241 | **/
242 | void lcdPrint(unsigned char *lByte)
243 | {
244 | for(;*lByte!='\0';lByte++)
245 | lcdWrite(*lByte);
246 | }
247 |
248 | /*** Function : lcdSetCursor
249 | ** Parameters : None
250 | ** Return : int,int
251 | ** Description : It will set row and column of the lcd
252 | **/
253 | void lcdSetCursor(int line,int col)
254 | {
255 | #if _LCD_TYPE_ == 1
256 | if(line==1)
257 | lcd_command(LCD_ADDRESS_ROW1 + col);
258 | else if(line == 2)
259 | lcd_command(LCD_ADDRESS_ROW2 + col);
260 | else if(line == 3)
261 | lcd_command(LCD_ADDRESS_ROW3 + col);
262 | else
263 | lcd_command(LCD_ADDRESS_ROW4 + col);
264 | #elif _LCD_TYPE_ == 2
265 | if(line==1)
266 | lcd_command(LCD_ADDRESS_ROW1 + col);
267 | else
268 | lcd_command(LCD_ADDRESS_ROW2 + col);
269 | #endif
270 | }
271 |
272 | /*** Function : lcdClear
273 | ** Parameters : None
274 | ** Return : None
275 | ** Description : It will Clear the LCD screen and DDRAM of the LCD
276 | **/
277 | void lcdClear(void)
278 | {
279 | lcd_command(LCD_CLEAR_ALSO_DDRAM);
280 | }
281 |
282 | /*** Function : lcdReset
283 | ** Parameters : None
284 | ** Return : None
285 | ** Description : It will Reset the LCD for 4-bit Mode
286 | **/
287 | void lcdReset(void)
288 | {
289 | LCD_D7_PORT &= ~LCD_D7_BIT;
290 | LCD_D6_PORT &= ~LCD_D6_BIT;
291 | LCD_D5_PORT |= LCD_D5_BIT;
292 | LCD_D4_PORT |= LCD_D4_BIT;
293 |
294 | lcdEnable();
295 | __delay_ms__(10);
296 | lcdEnable();
297 | __delay_ms__(10);
298 | lcdEnable();
299 | __delay_ms__(10);
300 |
301 | LCD_D7_PORT &= ~LCD_D7_BIT;
302 | LCD_D6_PORT &= ~LCD_D6_BIT;
303 | LCD_D5_PORT |= LCD_D5_BIT;
304 | LCD_D4_PORT &= ~LCD_D4_BIT;
305 |
306 | lcdEnable();
307 | __delay_ms__(10);
308 | }
309 |
310 | /*** Function : lcdBegin
311 | ** Parameters : None
312 | ** Return : None
313 | ** Description : It will initiate the lcd
314 | **/
315 | void lcdBegin(void)
316 | {
317 | lcd_port_init();
318 | #if LCD_MODE == 1
319 | lcd_command(LCD_8BIT_2_LINE_5_x_7);
320 | _lcd_delay;
321 | #elif LCD_MODE == 2
322 | lcdReset();
323 | lcd_command(LCD_4BIT_2_LINE_5_x_7);
324 | #endif
325 | lcd_command(LCD_DISPLAY_ON_CURSOR_OFF);
326 | lcd_command(LCD_CLEAR_ALSO_DDRAM);
327 | lcd_command(LCD_ADDRESS_ROW1);
328 | }
329 |
330 | /*** Function : lcdWriteint
331 | ** Parameters : None
332 | ** Return : None
333 | ** Description : It will initiate the lcd
334 | **/
335 | void lcdWriteint(signed int num)
336 | {
337 | char *tempBuffer;
338 | sprintf(tempBuffer,"%d",num);
339 | lcdPrint((unsigned char*)tempBuffer);
340 | }
341 |
342 |
343 |
--------------------------------------------------------------------------------
/IO/io.c:
--------------------------------------------------------------------------------
1 | /***************************************************************************************************************
2 | This file is part of Library for 8051.
3 |
4 | Library for 8051 is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Library for 8051 is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Library for 8051. If not, see .
16 | /**************************************************************************************************************/
17 |
18 |
19 |
20 | /***
21 | ** File : io.c
22 | ** Author : Sriharsha
23 | ** Website : www.zuna.in
24 | ** Email : helpzuna@gmail.com
25 | ** Description: This is the io driver for 8051 family MCU's
26 | ***/
27 |
28 | #include "io.h"
29 |
30 | /*** Function : digitalWrite
31 | ** Parameters : unsigned char,unsigned char (Pin Number,State->HIGH/LOW)
32 | ** Return : None
33 | ** Description : It will Write the value to port
34 | **/
35 | void digitalWrite(unsigned char PinNo,unsigned char PinState)
36 | {
37 | if(PinNo < IO_MAX)
38 | {
39 | switch(PinNo % IO_MAX)
40 | {
41 | case 0 : if(PinState) PORT0OUT |= 1 << 0; else PORT0OUT &= (1 << 0); break;
42 | case 1 : if(PinState) PORT0OUT |= 1 << 1; else PORT0OUT &= (1 << 1); break;
43 | case 2 : if(PinState) PORT0OUT |= 1 << 2; else PORT0OUT &= (1 << 2); break;
44 | case 3 : if(PinState) PORT0OUT |= 1 << 3; else PORT0OUT &= (1 << 3); break;
45 | case 4 : if(PinState) PORT0OUT |= 1 << 4; else PORT0OUT &= (1 << 4); break;
46 | case 5 : if(PinState) PORT0OUT |= 1 << 5; else PORT0OUT &= (1 << 5); break;
47 | case 6 : if(PinState) PORT0OUT |= 1 << 6; else PORT0OUT &= (1 << 6); break;
48 | case 7 : if(PinState) PORT0OUT |= 1 << 7; else PORT0OUT &= (1 << 7); break;
49 | }
50 | }
51 | else if (PiNo < (IO_MAX * 2) && (PiNo > (IO_MAX)))
52 | {
53 | switch(PinNo % IO_MAX)
54 | {
55 | case 0 : if(PinState) PORT1OUT |= 1 << 0; else PORT1OUT &= (1 << 0); break;
56 | case 1 : if(PinState) PORT1OUT |= 1 << 1; else PORT1OUT &= (1 << 1); break;
57 | case 2 : if(PinState) PORT1OUT |= 1 << 2; else PORT1OUT &= (1 << 2); break;
58 | case 3 : if(PinState) PORT1OUT |= 1 << 3; else PORT1OUT &= (1 << 3); break;
59 | case 4 : if(PinState) PORT1OUT |= 1 << 4; else PORT1OUT &= (1 << 4); break;
60 | case 5 : if(PinState) PORT1OUT |= 1 << 5; else PORT1OUT &= (1 << 5); break;
61 | case 6 : if(PinState) PORT1OUT |= 1 << 6; else PORT1OUT &= (1 << 6); break;
62 | case 7 : if(PinState) PORT1OUT |= 1 << 7; else PORT1OUT &= (1 << 7); break;
63 | case 7 : if(PinState) PORT1OUT |= 1 << 7; else PORT1OUT &= (1 << 7); break;
64 | }
65 | }
66 | else if (PiNo < (IO_MAX * 3) && (PiNo > (IO_MAX * 2)))
67 | {
68 | switch(PinNo % IO_MAX)
69 | {
70 | case 0 : if(PinState) PORT2OUT |= 1 << 0; else PORT2OUT &= (1 << 0); break;
71 | case 1 : if(PinState) PORT2OUT |= 1 << 1; else PORT2OUT &= (1 << 1); break;
72 | case 2 : if(PinState) PORT2OUT |= 1 << 2; else PORT2OUT &= (1 << 2); break;
73 | case 3 : if(PinState) PORT2OUT |= 1 << 3; else PORT2OUT &= (1 << 3); break;
74 | case 4 : if(PinState) PORT2OUT |= 1 << 4; else PORT2OUT &= (1 << 4); break;
75 | case 5 : if(PinState) PORT2OUT |= 1 << 5; else PORT2OUT &= (1 << 5); break;
76 | case 6 : if(PinState) PORT2OUT |= 1 << 6; else PORT2OUT &= (1 << 6); break;
77 | case 7 : if(PinState) PORT2OUT |= 1 << 7; else PORT2OUT &= (1 << 7); break;
78 | }
79 | }
80 | else if (PiNo < (IO_MAX * 4) && (PiNo > (IO_MAX * 3)))
81 | {
82 | switch(PinNo % IO_MAX)
83 | {
84 | case 0 : if(PinState) PORT3OUT |= 1 << 0; else PORT3OUT &= (1 << 0); break;
85 | case 1 : if(PinState) PORT3OUT |= 1 << 1; else PORT3OUT &= (1 << 1); break;
86 | case 2 : if(PinState) PORT3OUT |= 1 << 2; else PORT3OUT &= (1 << 2); break;
87 | case 3 : if(PinState) PORT3OUT |= 1 << 3; else PORT3OUT &= (1 << 3); break;
88 | case 4 : if(PinState) PORT3OUT |= 1 << 4; else PORT3OUT &= (1 << 4); break;
89 | case 5 : if(PinState) PORT3OUT |= 1 << 5; else PORT3OUT &= (1 << 5); break;
90 | case 6 : if(PinState) PORT3OUT |= 1 << 6; else PORT3OUT &= (1 << 6); break;
91 | case 7 : if(PinState) PORT3OUT |= 1 << 7; else PORT3OUT &= (1 << 7); break;
92 | }
93 | }
94 | }
95 |
96 | /*** Function : digitalRead
97 | ** Parameters : unsigned char(Pin Number)
98 | ** Return : Pin State (HIGH,LOW)
99 | ** Description : It will Read the data from PORT
100 | **/
101 | unsigned char digitalRead(unsigned char PinNo)
102 | {
103 | if(PinNo < IO_MAX)
104 | {
105 | switch(PinNo % IO_MAX)
106 | {
107 | case 0 : if(PORT0IN & 0x01) return HIGH; else return LOW;
108 | case 1 : if(PORT0IN & 0x02) return HIGH; else return LOW;
109 | case 2 : if(PORT0IN & 0x04) return HIGH; else return LOW;
110 | case 3 : if(PORT0IN & 0x08) return HIGH; else return LOW;
111 | case 4 : if(PORT0IN & 0x10) return HIGH; else return LOW;
112 | case 5 : if(PORT0IN & 0x20) return HIGH; else return LOW;
113 | case 6 : if(PORT0IN & 0x40) return HIGH; else return LOW;
114 | case 7 : if(PORT0IN & 0x80) return HIGH; else return LOW;
115 | }
116 | }
117 | else if (PiNo < (IO_MAX * 2) && (PiNo > (IO_MAX)))
118 | {
119 | switch(PinNo % IO_MAX)
120 | {
121 | case 0 : if(PORT1IN & 0x01) return HIGH; else return LOW;
122 | case 1 : if(PORT1IN & 0x02) return HIGH; else return LOW;
123 | case 2 : if(PORT1IN & 0x04) return HIGH; else return LOW;
124 | case 3 : if(PORT1IN & 0x08) return HIGH; else return LOW;
125 | case 4 : if(PORT1IN & 0x10) return HIGH; else return LOW;
126 | case 5 : if(PORT1IN & 0x20) return HIGH; else return LOW;
127 | case 6 : if(PORT1IN & 0x40) return HIGH; else return LOW;
128 | case 7 : if(PORT1IN & 0x80) return HIGH; else return LOW;
129 | }
130 | }
131 | else if (PiNo < (IO_MAX * 3) && (PiNo > (IO_MAX * 2)))
132 | {
133 | switch(PinNo % IO_MAX)
134 | {
135 | case 0 : if(PORT2IN & 0x01) return HIGH; else return LOW;
136 | case 1 : if(PORT2IN & 0x02) return HIGH; else return LOW;
137 | case 2 : if(PORT2IN & 0x04) return HIGH; else return LOW;
138 | case 3 : if(PORT2IN & 0x08) return HIGH; else return LOW;
139 | case 4 : if(PORT2IN & 0x10) return HIGH; else return LOW;
140 | case 5 : if(PORT2IN & 0x20) return HIGH; else return LOW;
141 | case 6 : if(PORT2IN & 0x40) return HIGH; else return LOW;
142 | case 7 : if(PORT2IN & 0x80) return HIGH; else return LOW;
143 | }
144 | }
145 | else if (PiNo < (IO_MAX * 4) && (PiNo > (IO_MAX * 3)))
146 | {
147 | switch(PinNo % IO_MAX)
148 | {
149 | case 0 : if(PORT3IN & 0x01) return HIGH; else return LOW;
150 | case 1 : if(PORT3IN & 0x02) return HIGH; else return LOW;
151 | case 2 : if(PORT3IN & 0x04) return HIGH; else return LOW;
152 | case 3 : if(PORT3IN & 0x08) return HIGH; else return LOW;
153 | case 4 : if(PORT3IN & 0x10) return HIGH; else return LOW;
154 | case 5 : if(PORT3IN & 0x20) return HIGH; else return LOW;
155 | case 6 : if(PORT3IN & 0x40) return HIGH; else return LOW;
156 | case 7 : if(PORT3IN & 0x80) return HIGH; else return LOW;
157 | }
158 | }
159 | }
160 |
161 | /*** Function : pinMode
162 | ** Parameters : unsigned char,unsigned char (Pin Number,PinDirection->INPUT/OUTPUT)
163 | ** Return : None
164 | ** Description : It will Set the direction of port
165 | **/
166 | void pinMode(unsigned char PinNo,unsigned char PinDirection)
167 | {
168 | if(PinNo < IO_MAX)
169 | {
170 | switch(PinNo % IO_MAX)
171 | {
172 | case 0 : if(PinState) PORT0DIR |= 1 << 0; else PORT0DIR &= (1 << 0); break;
173 | case 1 : if(PinState) PORT0DIR |= 1 << 1; else PORT0DIR &= (1 << 1); break;
174 | case 2 : if(PinState) PORT0DIR |= 1 << 2; else PORT0DIR &= (1 << 2); break;
175 | case 3 : if(PinState) PORT0DIR |= 1 << 3; else PORT0DIR &= (1 << 3); break;
176 | case 4 : if(PinState) PORT0DIR |= 1 << 4; else PORT0DIR &= (1 << 4); break;
177 | case 5 : if(PinState) PORT0DIR |= 1 << 5; else PORT0DIR &= (1 << 5); break;
178 | case 6 : if(PinState) PORT0DIR |= 1 << 6; else PORT0DIR &= (1 << 6); break;
179 | case 7 : if(PinState) PORT0DIR |= 1 << 7; else PORT0DIR &= (1 << 7); break;
180 | }
181 | }
182 | else if (PiNo < (IO_MAX * 2) && (PiNo > (IO_MAX)))
183 | {
184 | switch(PinNo % IO_MAX)
185 | {
186 | case 0 : if(PinState) PORT1DIR |= 1 << 0; else PORT1DIR &= (1 << 0); break;
187 | case 1 : if(PinState) PORT1DIR |= 1 << 1; else PORT1DIR &= (1 << 1); break;
188 | case 2 : if(PinState) PORT1DIR |= 1 << 2; else PORT1DIR &= (1 << 2); break;
189 | case 3 : if(PinState) PORT1DIR |= 1 << 3; else PORT1DIR &= (1 << 3); break;
190 | case 4 : if(PinState) PORT1DIR |= 1 << 4; else PORT1DIR &= (1 << 4); break;
191 | case 5 : if(PinState) PORT1DIR |= 1 << 5; else PORT1DIR &= (1 << 5); break;
192 | case 6 : if(PinState) PORT1DIR |= 1 << 6; else PORT1DIR &= (1 << 6); break;
193 | case 7 : if(PinState) PORT1DIR |= 1 << 7; else PORT1DIR &= (1 << 7); break;
194 | case 7 : if(PinState) PORT1DIR |= 1 << 7; else PORT1DIR &= (1 << 7); break;
195 | }
196 | }
197 | else if (PiNo < (IO_MAX * 3) && (PiNo > (IO_MAX * 2)))
198 | {
199 | switch(PinNo % IO_MAX)
200 | {
201 | case 0 : if(PinState) PORT2DIR |= 1 << 0; else PORT2DIR &= (1 << 0); break;
202 | case 1 : if(PinState) PORT2DIR |= 1 << 1; else PORT2DIR &= (1 << 1); break;
203 | case 2 : if(PinState) PORT2DIR |= 1 << 2; else PORT2DIR &= (1 << 2); break;
204 | case 3 : if(PinState) PORT2DIR |= 1 << 3; else PORT2DIR &= (1 << 3); break;
205 | case 4 : if(PinState) PORT2DIR |= 1 << 4; else PORT2DIR &= (1 << 4); break;
206 | case 5 : if(PinState) PORT2DIR |= 1 << 5; else PORT2DIR &= (1 << 5); break;
207 | case 6 : if(PinState) PORT2DIR |= 1 << 6; else PORT2DIR &= (1 << 6); break;
208 | case 7 : if(PinState) PORT2DIR |= 1 << 7; else PORT2DIR &= (1 << 7); break;
209 | }
210 | }
211 | else if (PiNo < (IO_MAX * 4) && (PiNo > (IO_MAX * 3)))
212 | {
213 | switch(PinNo % IO_MAX)
214 | {
215 | case 0 : if(PinState) PORT3DIR |= 1 << 0; else PORT3DIR &= (1 << 0); break;
216 | case 1 : if(PinState) PORT3DIR |= 1 << 1; else PORT3DIR &= (1 << 1); break;
217 | case 2 : if(PinState) PORT3DIR |= 1 << 2; else PORT3DIR &= (1 << 2); break;
218 | case 3 : if(PinState) PORT3DIR |= 1 << 3; else PORT3DIR &= (1 << 3); break;
219 | case 4 : if(PinState) PORT3DIR |= 1 << 4; else PORT3DIR &= (1 << 4); break;
220 | case 5 : if(PinState) PORT3DIR |= 1 << 5; else PORT3DIR &= (1 << 5); break;
221 | case 6 : if(PinState) PORT3DIR |= 1 << 6; else PORT3DIR &= (1 << 6); break;
222 | case 7 : if(PinState) PORT3DIR |= 1 << 7; else PORT3DIR &= (1 << 7); break;
223 | }
224 | }
225 | }
--------------------------------------------------------------------------------
/LICENCE:
--------------------------------------------------------------------------------
1 | This file includes licensing information for parts of Library for 8051.
2 |
3 | first, the gnu general public license, which covers code
4 | of the Library for 8051
5 |
6 |
7 | .....................................................................
8 |
9 |
10 | GNU GENERAL PUBLIC LICENSE
11 | Version 2, June 1991
12 |
13 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.
14 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 | Everyone is permitted to copy and distribute verbatim copies
16 | of this license document, but changing it is not allowed.
17 |
18 | Preamble
19 |
20 | The licenses for most software are designed to take away your
21 | freedom to share and change it. By contrast, the GNU General Public
22 | License is intended to guarantee your freedom to share and change free
23 | software--to make sure the software is free for all its users. This
24 | General Public License applies to most of the Free Software
25 | Foundation's software and to any other program whose authors commit to
26 | using it. (Some other Free Software Foundation software is covered by
27 | the GNU Library General Public License instead.) You can apply it to
28 | your programs, too.
29 |
30 | When we speak of free software, we are referring to freedom, not
31 | price. Our General Public Licenses are designed to make sure that you
32 | have the freedom to distribute copies of free software (and charge for
33 | this service if you wish), that you receive source code or can get it
34 | if you want it, that you can change the software or use pieces of it
35 | in new free programs; and that you know you can do these things.
36 |
37 | To protect your rights, we need to make restrictions that forbid
38 | anyone to deny you these rights or to ask you to surrender the rights.
39 | These restrictions translate to certain responsibilities for you if you
40 | distribute copies of the software, or if you modify it.
41 |
42 | For example, if you distribute copies of such a program, whether
43 | gratis or for a fee, you must give the recipients all the rights that
44 | you have. You must make sure that they, too, receive or can get the
45 | source code. And you must show them these terms so they know their
46 | rights.
47 |
48 | We protect your rights with two steps: (1) copyright the software, and
49 | (2) offer you this license which gives you legal permission to copy,
50 | distribute and/or modify the software.
51 |
52 | Also, for each author's protection and ours, we want to make certain
53 | that everyone understands that there is no warranty for this free
54 | software. If the software is modified by someone else and passed on, we
55 | want its recipients to know that what they have is not the original, so
56 | that any problems introduced by others will not reflect on the original
57 | authors' reputations.
58 |
59 | Finally, any free program is threatened constantly by software
60 | patents. We wish to avoid the danger that redistributors of a free
61 | program will individually obtain patent licenses, in effect making the
62 | program proprietary. To prevent this, we have made it clear that any
63 | patent must be licensed for everyone's free use or not licensed at all.
64 |
65 | The precise terms and conditions for copying, distribution and
66 | modification follow.
67 |
68 | GNU GENERAL PUBLIC LICENSE
69 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
70 |
71 | 0. This License applies to any program or other work which contains
72 | a notice placed by the copyright holder saying it may be distributed
73 | under the terms of this General Public License. The "Program", below,
74 | refers to any such program or work, and a "work based on the Program"
75 | means either the Program or any derivative work under copyright law:
76 | that is to say, a work containing the Program or a portion of it,
77 | either verbatim or with modifications and/or translated into another
78 | language. (Hereinafter, translation is included without limitation in
79 | the term "modification".) Each licensee is addressed as "you".
80 |
81 | Activities other than copying, distribution and modification are not
82 | covered by this License; they are outside its scope. The act of
83 | running the Program is not restricted, and the output from the Program
84 | is covered only if its contents constitute a work based on the
85 | Program (independent of having been made by running the Program).
86 | Whether that is true depends on what the Program does.
87 |
88 | 1. You may copy and distribute verbatim copies of the Program's
89 | source code as you receive it, in any medium, provided that you
90 | conspicuously and appropriately publish on each copy an appropriate
91 | copyright notice and disclaimer of warranty; keep intact all the
92 | notices that refer to this License and to the absence of any warranty;
93 | and give any other recipients of the Program a copy of this License
94 | along with the Program.
95 |
96 | You may charge a fee for the physical act of transferring a copy, and
97 | you may at your option offer warranty protection in exchange for a fee.
98 |
99 | 2. You may modify your copy or copies of the Program or any portion
100 | of it, thus forming a work based on the Program, and copy and
101 | distribute such modifications or work under the terms of Section 1
102 | above, provided that you also meet all of these conditions:
103 |
104 | a) You must cause the modified files to carry prominent notices
105 | stating that you changed the files and the date of any change.
106 |
107 | b) You must cause any work that you distribute or publish, that in
108 | whole or in part contains or is derived from the Program or any
109 | part thereof, to be licensed as a whole at no charge to all third
110 | parties under the terms of this License.
111 |
112 | c) If the modified program normally reads commands interactively
113 | when run, you must cause it, when started running for such
114 | interactive use in the most ordinary way, to print or display an
115 | announcement including an appropriate copyright notice and a
116 | notice that there is no warranty (or else, saying that you provide
117 | a warranty) and that users may redistribute the program under
118 | these conditions, and telling the user how to view a copy of this
119 | License. (Exception: if the Program itself is interactive but
120 | does not normally print such an announcement, your work based on
121 | the Program is not required to print an announcement.)
122 |
123 | These requirements apply to the modified work as a whole. If
124 | identifiable sections of that work are not derived from the Program,
125 | and can be reasonably considered independent and separate works in
126 | themselves, then this License, and its terms, do not apply to those
127 | sections when you distribute them as separate works. But when you
128 | distribute the same sections as part of a whole which is a work based
129 | on the Program, the distribution of the whole must be on the terms of
130 | this License, whose permissions for other licensees extend to the
131 | entire whole, and thus to each and every part regardless of who wrote it.
132 |
133 | Thus, it is not the intent of this section to claim rights or contest
134 | your rights to work written entirely by you; rather, the intent is to
135 | exercise the right to control the distribution of derivative or
136 | collective works based on the Program.
137 |
138 | In addition, mere aggregation of another work not based on the Program
139 | with the Program (or with a work based on the Program) on a volume of
140 | a storage or distribution medium does not bring the other work under
141 | the scope of this License.
142 |
143 | 3. You may copy and distribute the Program (or a work based on it,
144 | under Section 2) in object code or executable form under the terms of
145 | Sections 1 and 2 above provided that you also do one of the following:
146 |
147 | a) Accompany it with the complete corresponding machine-readable
148 | source code, which must be distributed under the terms of Sections
149 | 1 and 2 above on a medium customarily used for software interchange; or,
150 |
151 | b) Accompany it with a written offer, valid for at least three
152 | years, to give any third party, for a charge no more than your
153 | cost of physically performing source distribution, a complete
154 | machine-readable copy of the corresponding source code, to be
155 | distributed under the terms of Sections 1 and 2 above on a medium
156 | customarily used for software interchange; or,
157 |
158 | c) Accompany it with the information you received as to the offer
159 | to distribute corresponding source code. (This alternative is
160 | allowed only for noncommercial distribution and only if you
161 | received the program in object code or executable form with such
162 | an offer, in accord with Subsection b above.)
163 |
164 | The source code for a work means the preferred form of the work for
165 | making modifications to it. For an executable work, complete source
166 | code means all the source code for all modules it contains, plus any
167 | associated interface definition files, plus the scripts used to
168 | control compilation and installation of the executable. However, as a
169 | special exception, the source code distributed need not include
170 | anything that is normally distributed (in either source or binary
171 | form) with the major components (compiler, kernel, and so on) of the
172 | operating system on which the executable runs, unless that component
173 | itself accompanies the executable.
174 |
175 | If distribution of executable or object code is made by offering
176 | access to copy from a designated place, then offering equivalent
177 | access to copy the source code from the same place counts as
178 | distribution of the source code, even though third parties are not
179 | compelled to copy the source along with the object code.
180 |
181 | 4. You may not copy, modify, sublicense, or distribute the Program
182 | except as expressly provided under this License. Any attempt
183 | otherwise to copy, modify, sublicense or distribute the Program is
184 | void, and will automatically terminate your rights under this License.
185 | However, parties who have received copies, or rights, from you under
186 | this License will not have their licenses terminated so long as such
187 | parties remain in full compliance.
188 |
189 | 5. You are not required to accept this License, since you have not
190 | signed it. However, nothing else grants you permission to modify or
191 | distribute the Program or its derivative works. These actions are
192 | prohibited by law if you do not accept this License. Therefore, by
193 | modifying or distributing the Program (or any work based on the
194 | Program), you indicate your acceptance of this License to do so, and
195 | all its terms and conditions for copying, distributing or modifying
196 | the Program or works based on it.
197 |
198 | 6. Each time you redistribute the Program (or any work based on the
199 | Program), the recipient automatically receives a license from the
200 | original licensor to copy, distribute or modify the Program subject to
201 | these terms and conditions. You may not impose any further
202 | restrictions on the recipients' exercise of the rights granted herein.
203 | You are not responsible for enforcing compliance by third parties to
204 | this License.
205 |
206 | 7. If, as a consequence of a court judgment or allegation of patent
207 | infringement or for any other reason (not limited to patent issues),
208 | conditions are imposed on you (whether by court order, agreement or
209 | otherwise) that contradict the conditions of this License, they do not
210 | excuse you from the conditions of this License. If you cannot
211 | distribute so as to satisfy simultaneously your obligations under this
212 | License and any other pertinent obligations, then as a consequence you
213 | may not distribute the Program at all. For example, if a patent
214 | license would not permit royalty-free redistribution of the Program by
215 | all those who receive copies directly or indirectly through you, then
216 | the only way you could satisfy both it and this License would be to
217 | refrain entirely from distribution of the Program.
218 |
219 | If any portion of this section is held invalid or unenforceable under
220 | any particular circumstance, the balance of the section is intended to
221 | apply and the section as a whole is intended to apply in other
222 | circumstances.
223 |
224 | It is not the purpose of this section to induce you to infringe any
225 | patents or other property right claims or to contest validity of any
226 | such claims; this section has the sole purpose of protecting the
227 | integrity of the free software distribution system, which is
228 | implemented by public license practices. Many people have made
229 | generous contributions to the wide range of software distributed
230 | through that system in reliance on consistent application of that
231 | system; it is up to the author/donor to decide if he or she is willing
232 | to distribute software through any other system and a licensee cannot
233 | impose that choice.
234 |
235 | This section is intended to make thoroughly clear what is believed to
236 | be a consequence of the rest of this License.
237 |
238 | 8. If the distribution and/or use of the Program is restricted in
239 | certain countries either by patents or by copyrighted interfaces, the
240 | original copyright holder who places the Program under this License
241 | may add an explicit geographical distribution limitation excluding
242 | those countries, so that distribution is permitted only in or among
243 | countries not thus excluded. In such case, this License incorporates
244 | the limitation as if written in the body of this License.
245 |
246 | 9. The Free Software Foundation may publish revised and/or new versions
247 | of the General Public License from time to time. Such new versions will
248 | be similar in spirit to the present version, but may differ in detail to
249 | address new problems or concerns.
250 |
251 | Each version is given a distinguishing version number. If the Program
252 | specifies a version number of this License which applies to it and "any
253 | later version", you have the option of following the terms and conditions
254 | either of that version or of any later version published by the Free
255 | Software Foundation. If the Program does not specify a version number of
256 | this License, you may choose any version ever published by the Free Software
257 | Foundation.
258 |
259 | 10. If you wish to incorporate parts of the Program into other free
260 | programs whose distribution conditions are different, write to the author
261 | to ask for permission. For software which is copyrighted by the Free
262 | Software Foundation, write to the Free Software Foundation; we sometimes
263 | make exceptions for this. Our decision will be guided by the two goals
264 | of preserving the free status of all derivatives of our free software and
265 | of promoting the sharing and reuse of software generally.
266 |
267 | NO WARRANTY
268 |
269 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
270 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
271 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
272 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
273 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
274 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
275 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
276 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
277 | REPAIR OR CORRECTION.
278 |
279 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
280 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
281 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
282 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
283 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
284 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
285 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
286 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
287 | POSSIBILITY OF SUCH DAMAGES.
288 |
289 |
290 |
291 | .....................................................................
292 |
293 | GNU LESSER GENERAL PUBLIC LICENSE
294 | Version 2.1, February 1999
295 |
296 | Copyright (C) 1991, 1999 Free Software Foundation, Inc.
297 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
298 | Everyone is permitted to copy and distribute verbatim copies
299 | of this license document, but changing it is not allowed.
300 |
301 | [This is the first released version of the Lesser GPL. It also counts
302 | as the successor of the GNU Library Public License, version 2, hence
303 | the version number 2.1.]
304 |
305 | Preamble
306 |
307 | The licenses for most software are designed to take away your
308 | freedom to share and change it. By contrast, the GNU General Public
309 | Licenses are intended to guarantee your freedom to share and change
310 | free software--to make sure the software is free for all its users.
311 |
312 | This license, the Lesser General Public License, applies to some
313 | specially designated software packages--typically libraries--of the
314 | Free Software Foundation and other authors who decide to use it. You
315 | can use it too, but we suggest you first think carefully about whether
316 | this license or the ordinary General Public License is the better
317 | strategy to use in any particular case, based on the explanations below.
318 |
319 | When we speak of free software, we are referring to freedom of use,
320 | not price. Our General Public Licenses are designed to make sure that
321 | you have the freedom to distribute copies of free software (and charge
322 | for this service if you wish); that you receive source code or can get
323 | it if you want it; that you can change the software and use pieces of
324 | it in new free programs; and that you are informed that you can do
325 | these things.
326 |
327 | To protect your rights, we need to make restrictions that forbid
328 | distributors to deny you these rights or to ask you to surrender these
329 | rights. These restrictions translate to certain responsibilities for
330 | you if you distribute copies of the library or if you modify it.
331 |
332 | For example, if you distribute copies of the library, whether gratis
333 | or for a fee, you must give the recipients all the rights that we gave
334 | you. You must make sure that they, too, receive or can get the source
335 | code. If you link other code with the library, you must provide
336 | complete object files to the recipients, so that they can relink them
337 | with the library after making changes to the library and recompiling
338 | it. And you must show them these terms so they know their rights.
339 |
340 | We protect your rights with a two-step method: (1) we copyright the
341 | library, and (2) we offer you this license, which gives you legal
342 | permission to copy, distribute and/or modify the library.
343 |
344 | To protect each distributor, we want to make it very clear that
345 | there is no warranty for the free library. Also, if the library is
346 | modified by someone else and passed on, the recipients should know
347 | that what they have is not the original version, so that the original
348 | author's reputation will not be affected by problems that might be
349 | introduced by others.
350 |
351 | Finally, software patents pose a constant threat to the existence of
352 | any free program. We wish to make sure that a company cannot
353 | effectively restrict the users of a free program by obtaining a
354 | restrictive license from a patent holder. Therefore, we insist that
355 | any patent license obtained for a version of the library must be
356 | consistent with the full freedom of use specified in this license.
357 |
358 | Most GNU software, including some libraries, is covered by the
359 | ordinary GNU General Public License. This license, the GNU Lesser
360 | General Public License, applies to certain designated libraries, and
361 | is quite different from the ordinary General Public License. We use
362 | this license for certain libraries in order to permit linking those
363 | libraries into non-free programs.
364 |
365 | When a program is linked with a library, whether statically or using
366 | a shared library, the combination of the two is legally speaking a
367 | combined work, a derivative of the original library. The ordinary
368 | General Public License therefore permits such linking only if the
369 | entire combination fits its criteria of freedom. The Lesser General
370 | Public License permits more lax criteria for linking other code with
371 | the library.
372 |
373 | We call this license the "Lesser" General Public License because it
374 | does Less to protect the user's freedom than the ordinary General
375 | Public License. It also provides other free software developers Less
376 | of an advantage over competing non-free programs. These disadvantages
377 | are the reason we use the ordinary General Public License for many
378 | libraries. However, the Lesser license provides advantages in certain
379 | special circumstances.
380 |
381 | For example, on rare occasions, there may be a special need to
382 | encourage the widest possible use of a certain library, so that it becomes
383 | a de-facto standard. To achieve this, non-free programs must be
384 | allowed to use the library. A more frequent case is that a free
385 | library does the same job as widely used non-free libraries. In this
386 | case, there is little to gain by limiting the free library to free
387 | software only, so we use the Lesser General Public License.
388 |
389 | In other cases, permission to use a particular library in non-free
390 | programs enables a greater number of people to use a large body of
391 | free software. For example, permission to use the GNU C Library in
392 | non-free programs enables many more people to use the whole GNU
393 | operating system, as well as its variant, the GNU/Linux operating
394 | system.
395 |
396 | Although the Lesser General Public License is Less protective of the
397 | users' freedom, it does ensure that the user of a program that is
398 | linked with the Library has the freedom and the wherewithal to run
399 | that program using a modified version of the Library.
400 |
401 | The precise terms and conditions for copying, distribution and
402 | modification follow. Pay close attention to the difference between a
403 | "work based on the library" and a "work that uses the library". The
404 | former contains code derived from the library, whereas the latter must
405 | be combined with the library in order to run.
406 |
407 | GNU LESSER GENERAL PUBLIC LICENSE
408 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
409 |
410 | 0. This License Agreement applies to any software library or other
411 | program which contains a notice placed by the copyright holder or
412 | other authorized party saying it may be distributed under the terms of
413 | this Lesser General Public License (also called "this License").
414 | Each licensee is addressed as "you".
415 |
416 | A "library" means a collection of software functions and/or data
417 | prepared so as to be conveniently linked with application programs
418 | (which use some of those functions and data) to form executables.
419 |
420 | The "Library", below, refers to any such software library or work
421 | which has been distributed under these terms. A "work based on the
422 | Library" means either the Library or any derivative work under
423 | copyright law: that is to say, a work containing the Library or a
424 | portion of it, either verbatim or with modifications and/or translated
425 | straightforwardly into another language. (Hereinafter, translation is
426 | included without limitation in the term "modification".)
427 |
428 | "Source code" for a work means the preferred form of the work for
429 | making modifications to it. For a library, complete source code means
430 | all the source code for all modules it contains, plus any associated
431 | interface definition files, plus the scripts used to control compilation
432 | and installation of the library.
433 |
434 | Activities other than copying, distribution and modification are not
435 | covered by this License; they are outside its scope. The act of
436 | running a program using the Library is not restricted, and output from
437 | such a program is covered only if its contents constitute a work based
438 | on the Library (independent of the use of the Library in a tool for
439 | writing it). Whether that is true depends on what the Library does
440 | and what the program that uses the Library does.
441 |
442 | 1. You may copy and distribute verbatim copies of the Library's
443 | complete source code as you receive it, in any medium, provided that
444 | you conspicuously and appropriately publish on each copy an
445 | appropriate copyright notice and disclaimer of warranty; keep intact
446 | all the notices that refer to this License and to the absence of any
447 | warranty; and distribute a copy of this License along with the
448 | Library.
449 |
450 | You may charge a fee for the physical act of transferring a copy,
451 | and you may at your option offer warranty protection in exchange for a
452 | fee.
453 |
454 | 2. You may modify your copy or copies of the Library or any portion
455 | of it, thus forming a work based on the Library, and copy and
456 | distribute such modifications or work under the terms of Section 1
457 | above, provided that you also meet all of these conditions:
458 |
459 | a) The modified work must itself be a software library.
460 |
461 | b) You must cause the files modified to carry prominent notices
462 | stating that you changed the files and the date of any change.
463 |
464 | c) You must cause the whole of the work to be licensed at no
465 | charge to all third parties under the terms of this License.
466 |
467 | d) If a facility in the modified Library refers to a function or a
468 | table of data to be supplied by an application program that uses
469 | the facility, other than as an argument passed when the facility
470 | is invoked, then you must make a good faith effort to ensure that,
471 | in the event an application does not supply such function or
472 | table, the facility still operates, and performs whatever part of
473 | its purpose remains meaningful.
474 |
475 | (For example, a function in a library to compute square roots has
476 | a purpose that is entirely well-defined independent of the
477 | application. Therefore, Subsection 2d requires that any
478 | application-supplied function or table used by this function must
479 | be optional: if the application does not supply it, the square
480 | root function must still compute square roots.)
481 |
482 | These requirements apply to the modified work as a whole. If
483 | identifiable sections of that work are not derived from the Library,
484 | and can be reasonably considered independent and separate works in
485 | themselves, then this License, and its terms, do not apply to those
486 | sections when you distribute them as separate works. But when you
487 | distribute the same sections as part of a whole which is a work based
488 | on the Library, the distribution of the whole must be on the terms of
489 | this License, whose permissions for other licensees extend to the
490 | entire whole, and thus to each and every part regardless of who wrote
491 | it.
492 |
493 | Thus, it is not the intent of this section to claim rights or contest
494 | your rights to work written entirely by you; rather, the intent is to
495 | exercise the right to control the distribution of derivative or
496 | collective works based on the Library.
497 |
498 | In addition, mere aggregation of another work not based on the Library
499 | with the Library (or with a work based on the Library) on a volume of
500 | a storage or distribution medium does not bring the other work under
501 | the scope of this License.
502 |
503 | 3. You may opt to apply the terms of the ordinary GNU General Public
504 | License instead of this License to a given copy of the Library. To do
505 | this, you must alter all the notices that refer to this License, so
506 | that they refer to the ordinary GNU General Public License, version 2,
507 | instead of to this License. (If a newer version than version 2 of the
508 | ordinary GNU General Public License has appeared, then you can specify
509 | that version instead if you wish.) Do not make any other change in
510 | these notices.
511 |
512 | Once this change is made in a given copy, it is irreversible for
513 | that copy, so the ordinary GNU General Public License applies to all
514 | subsequent copies and derivative works made from that copy.
515 |
516 | This option is useful when you wish to copy part of the code of
517 | the Library into a program that is not a library.
518 |
519 | 4. You may copy and distribute the Library (or a portion or
520 | derivative of it, under Section 2) in object code or executable form
521 | under the terms of Sections 1 and 2 above provided that you accompany
522 | it with the complete corresponding machine-readable source code, which
523 | must be distributed under the terms of Sections 1 and 2 above on a
524 | medium customarily used for software interchange.
525 |
526 | If distribution of object code is made by offering access to copy
527 | from a designated place, then offering equivalent access to copy the
528 | source code from the same place satisfies the requirement to
529 | distribute the source code, even though third parties are not
530 | compelled to copy the source along with the object code.
531 |
532 | 5. A program that contains no derivative of any portion of the
533 | Library, but is designed to work with the Library by being compiled or
534 | linked with it, is called a "work that uses the Library". Such a
535 | work, in isolation, is not a derivative work of the Library, and
536 | therefore falls outside the scope of this License.
537 |
538 | However, linking a "work that uses the Library" with the Library
539 | creates an executable that is a derivative of the Library (because it
540 | contains portions of the Library), rather than a "work that uses the
541 | library". The executable is therefore covered by this License.
542 | Section 6 states terms for distribution of such executables.
543 |
544 | When a "work that uses the Library" uses material from a header file
545 | that is part of the Library, the object code for the work may be a
546 | derivative work of the Library even though the source code is not.
547 | Whether this is true is especially significant if the work can be
548 | linked without the Library, or if the work is itself a library. The
549 | threshold for this to be true is not precisely defined by law.
550 |
551 | If such an object file uses only numerical parameters, data
552 | structure layouts and accessors, and small macros and small inline
553 | functions (ten lines or less in length), then the use of the object
554 | file is unrestricted, regardless of whether it is legally a derivative
555 | work. (Executables containing this object code plus portions of the
556 | Library will still fall under Section 6.)
557 |
558 | Otherwise, if the work is a derivative of the Library, you may
559 | distribute the object code for the work under the terms of Section 6.
560 | Any executables containing that work also fall under Section 6,
561 | whether or not they are linked directly with the Library itself.
562 |
563 | 6. As an exception to the Sections above, you may also combine or
564 | link a "work that uses the Library" with the Library to produce a
565 | work containing portions of the Library, and distribute that work
566 | under terms of your choice, provided that the terms permit
567 | modification of the work for the customer's own use and reverse
568 | engineering for debugging such modifications.
569 |
570 | You must give prominent notice with each copy of the work that the
571 | Library is used in it and that the Library and its use are covered by
572 | this License. You must supply a copy of this License. If the work
573 | during execution displays copyright notices, you must include the
574 | copyright notice for the Library among them, as well as a reference
575 | directing the user to the copy of this License. Also, you must do one
576 | of these things:
577 |
578 | a) Accompany the work with the complete corresponding
579 | machine-readable source code for the Library including whatever
580 | changes were used in the work (which must be distributed under
581 | Sections 1 and 2 above); and, if the work is an executable linked
582 | with the Library, with the complete machine-readable "work that
583 | uses the Library", as object code and/or source code, so that the
584 | user can modify the Library and then relink to produce a modified
585 | executable containing the modified Library. (It is understood
586 | that the user who changes the contents of definitions files in the
587 | Library will not necessarily be able to recompile the application
588 | to use the modified definitions.)
589 |
590 | b) Use a suitable shared library mechanism for linking with the
591 | Library. A suitable mechanism is one that (1) uses at run time a
592 | copy of the library already present on the user's computer system,
593 | rather than copying library functions into the executable, and (2)
594 | will operate properly with a modified version of the library, if
595 | the user installs one, as long as the modified version is
596 | interface-compatible with the version that the work was made with.
597 |
598 | c) Accompany the work with a written offer, valid for at
599 | least three years, to give the same user the materials
600 | specified in Subsection 6a, above, for a charge no more
601 | than the cost of performing this distribution.
602 |
603 | d) If distribution of the work is made by offering access to copy
604 | from a designated place, offer equivalent access to copy the above
605 | specified materials from the same place.
606 |
607 | e) Verify that the user has already received a copy of these
608 | materials or that you have already sent this user a copy.
609 |
610 | For an executable, the required form of the "work that uses the
611 | Library" must include any data and utility programs needed for
612 | reproducing the executable from it. However, as a special exception,
613 | the materials to be distributed need not include anything that is
614 | normally distributed (in either source or binary form) with the major
615 | components (compiler, kernel, and so on) of the operating system on
616 | which the executable runs, unless that component itself accompanies
617 | the executable.
618 |
619 | It may happen that this requirement contradicts the license
620 | restrictions of other proprietary libraries that do not normally
621 | accompany the operating system. Such a contradiction means you cannot
622 | use both them and the Library together in an executable that you
623 | distribute.
624 |
625 | 7. You may place library facilities that are a work based on the
626 | Library side-by-side in a single library together with other library
627 | facilities not covered by this License, and distribute such a combined
628 | library, provided that the separate distribution of the work based on
629 | the Library and of the other library facilities is otherwise
630 | permitted, and provided that you do these two things:
631 |
632 | a) Accompany the combined library with a copy of the same work
633 | based on the Library, uncombined with any other library
634 | facilities. This must be distributed under the terms of the
635 | Sections above.
636 |
637 | b) Give prominent notice with the combined library of the fact
638 | that part of it is a work based on the Library, and explaining
639 | where to find the accompanying uncombined form of the same work.
640 |
641 | 8. You may not copy, modify, sublicense, link with, or distribute
642 | the Library except as expressly provided under this License. Any
643 | attempt otherwise to copy, modify, sublicense, link with, or
644 | distribute the Library is void, and will automatically terminate your
645 | rights under this License. However, parties who have received copies,
646 | or rights, from you under this License will not have their licenses
647 | terminated so long as such parties remain in full compliance.
648 |
649 | 9. You are not required to accept this License, since you have not
650 | signed it. However, nothing else grants you permission to modify or
651 | distribute the Library or its derivative works. These actions are
652 | prohibited by law if you do not accept this License. Therefore, by
653 | modifying or distributing the Library (or any work based on the
654 | Library), you indicate your acceptance of this License to do so, and
655 | all its terms and conditions for copying, distributing or modifying
656 | the Library or works based on it.
657 |
658 | 10. Each time you redistribute the Library (or any work based on the
659 | Library), the recipient automatically receives a license from the
660 | original licensor to copy, distribute, link with or modify the Library
661 | subject to these terms and conditions. You may not impose any further
662 | restrictions on the recipients' exercise of the rights granted herein.
663 | You are not responsible for enforcing compliance by third parties with
664 | this License.
665 |
666 | 11. If, as a consequence of a court judgment or allegation of patent
667 | infringement or for any other reason (not limited to patent issues),
668 | conditions are imposed on you (whether by court order, agreement or
669 | otherwise) that contradict the conditions of this License, they do not
670 | excuse you from the conditions of this License. If you cannot
671 | distribute so as to satisfy simultaneously your obligations under this
672 | License and any other pertinent obligations, then as a consequence you
673 | may not distribute the Library at all. For example, if a patent
674 | license would not permit royalty-free redistribution of the Library by
675 | all those who receive copies directly or indirectly through you, then
676 | the only way you could satisfy both it and this License would be to
677 | refrain entirely from distribution of the Library.
678 |
679 | If any portion of this section is held invalid or unenforceable under any
680 | particular circumstance, the balance of the section is intended to apply,
681 | and the section as a whole is intended to apply in other circumstances.
682 |
683 | It is not the purpose of this section to induce you to infringe any
684 | patents or other property right claims or to contest validity of any
685 | such claims; this section has the sole purpose of protecting the
686 | integrity of the free software distribution system which is
687 | implemented by public license practices. Many people have made
688 | generous contributions to the wide range of software distributed
689 | through that system in reliance on consistent application of that
690 | system; it is up to the author/donor to decide if he or she is willing
691 | to distribute software through any other system and a licensee cannot
692 | impose that choice.
693 |
694 | This section is intended to make thoroughly clear what is believed to
695 | be a consequence of the rest of this License.
696 |
697 | 12. If the distribution and/or use of the Library is restricted in
698 | certain countries either by patents or by copyrighted interfaces, the
699 | original copyright holder who places the Library under this License may add
700 | an explicit geographical distribution limitation excluding those countries,
701 | so that distribution is permitted only in or among countries not thus
702 | excluded. In such case, this License incorporates the limitation as if
703 | written in the body of this License.
704 |
705 | 13. The Free Software Foundation may publish revised and/or new
706 | versions of the Lesser General Public License from time to time.
707 | Such new versions will be similar in spirit to the present version,
708 | but may differ in detail to address new problems or concerns.
709 |
710 | Each version is given a distinguishing version number. If the Library
711 | specifies a version number of this License which applies to it and
712 | "any later version", you have the option of following the terms and
713 | conditions either of that version or of any later version published by
714 | the Free Software Foundation. If the Library does not specify a
715 | license version number, you may choose any version ever published by
716 | the Free Software Foundation.
717 |
718 | 14. If you wish to incorporate parts of the Library into other free
719 | programs whose distribution conditions are incompatible with these,
720 | write to the author to ask for permission. For software which is
721 | copyrighted by the Free Software Foundation, write to the Free
722 | Software Foundation; we sometimes make exceptions for this. Our
723 | decision will be guided by the two goals of preserving the free status
724 | of all derivatives of our free software and of promoting the sharing
725 | and reuse of software generally.
726 |
727 | NO WARRANTY
728 |
729 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
730 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
731 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
732 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
733 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
734 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
735 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
736 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
737 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
738 |
739 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
740 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
741 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
742 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
743 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
744 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
745 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
746 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
747 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
748 | DAMAGES.
--------------------------------------------------------------------------------