From: vl_garistov Date: Wed, 24 Feb 2021 01:28:57 +0000 (+0200) Subject: added LCD example and one more 7-segment example X-Git-Url: https://kolegite.com/gitweb/?a=commitdiff_plain;h=0c53e428294ac463c1b84edb4c7d97a6daa00326;p=vmks.git added LCD example and one more 7-segment example --- diff --git a/Datasheets/HD44780.pdf b/Datasheets/HD44780.pdf new file mode 100644 index 0000000..5cd5f79 Binary files /dev/null and b/Datasheets/HD44780.pdf differ diff --git a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.PDF b/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.PDF deleted file mode 100644 index dd885da..0000000 Binary files a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.PDF and /dev/null differ diff --git a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.ino b/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.ino index b14da34..ec34961 100644 --- a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.ino +++ b/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.ino @@ -13,8 +13,7 @@ int print_dec(uint16_t value); int print_digit(uint8_t position, uint8_t digit); -void timer_init(void); -void gpio_init(void); +void emulate_timer_ISR(void); const uint8_t segm_pins[8] = {A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, F_PIN, G_PIN, DP_PIN}; const uint8_t en_pins[4] = {EN0_PIN, EN1_PIN, EN2_PIN, EN3_PIN}; @@ -45,8 +44,17 @@ volatile uint8_t current_digit = 0; void setup() { - gpio_init(); - timer_init(); + uint8_t i; + for (i = 0; i < 4; i++) + { + pinMode(en_pins[i], OUTPUT); + digitalWrite(en_pins[i], HIGH); + } + for (i = 0; i < 8; i++) + { + pinMode(segm_pins[i], OUTPUT); + digitalWrite(segm_pins[i], HIGH); + } } void loop() @@ -54,7 +62,13 @@ void loop() for (uint16_t cnt = 9999; cnt > 0; cnt--) { print_dec(cnt); - delay(100); + + // This is garbage, don't use it! + for(uint8_t i = 0; i < 10; i++) + { + delay(10); + emulate_timer_ISR(); + } } delay(3000); } @@ -87,7 +101,7 @@ int print_digit(uint8_t position, uint8_t digit) return 0; } -ISR(TIMER1_OVF_vect) +void emulate_timer_ISR(void) { digitalWrite(en_pins[current_digit], HIGH); @@ -104,37 +118,3 @@ ISR(TIMER1_OVF_vect) digitalWrite(en_pins[current_digit], LOW); } - -void gpio_init(void) -{ - uint8_t i; - for (i = 0; i < 4; i++) - { - pinMode(en_pins[i], OUTPUT); - digitalWrite(en_pins[i], HIGH); - } - for (i = 0; i < 8; i++) - { - pinMode(segm_pins[i], OUTPUT); - digitalWrite(segm_pins[i], HIGH); - } -} - -void timer_init(void) -{ - noInterrupts(); - - // After clearing TCCR1B the timer is stopped - TCCR1B = 0; - TCNT1 = 0; - - TCCR1A = (1 << WGM11); - TCCR1B |= (1 << WGM12) | (1 << WGM13); - TIMSK1 = (1 << TOIE1); - - // Set frequency to 1kHz - ICR1 = 1999; - TCCR1B |= (1 << CS11); - - interrupts(); -} diff --git a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.pdsprj b/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.pdsprj deleted file mode 100644 index d482f6c..0000000 Binary files a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.pdsprj and /dev/null differ diff --git a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.pdsprj.DESKTOP-DNPR54D.Cartogan.workspace b/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.pdsprj.DESKTOP-DNPR54D.Cartogan.workspace deleted file mode 100644 index 1c21abc..0000000 --- a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.pdsprj.DESKTOP-DNPR54D.Cartogan.workspace +++ /dev/null @@ -1,101 +0,0 @@ - - - - 2c0000000200000003000000ffffffffffffffffffffffffffffffffab0000000d000000d606000004040000 - - - - - - - - 542 - No - 100 - 120 - 100 - - - - - 83 - No - Yes - 83 - Yes - No - No - Yes - 0 - 83 - 100 - 83 - 0 - - - - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000100 - - - - - 2 - Yes - 2 - Yes - Yes - 00000020 - - - - - diff --git a/Examples/7-segm_raw_dynamic/Backup Of 7-segm_raw_dynamic.pdsbak b/Examples/7-segm_raw_dynamic/Backup Of 7-segm_raw_dynamic.pdsbak deleted file mode 100644 index 9bed130..0000000 Binary files a/Examples/7-segm_raw_dynamic/Backup Of 7-segm_raw_dynamic.pdsbak and /dev/null differ diff --git a/Examples/7-segm_raw_dynamic/Last Loaded 7-segm_raw_dynamic.pdsbak b/Examples/7-segm_raw_dynamic/Last Loaded 7-segm_raw_dynamic.pdsbak deleted file mode 100644 index 8acc458..0000000 Binary files a/Examples/7-segm_raw_dynamic/Last Loaded 7-segm_raw_dynamic.pdsbak and /dev/null differ diff --git a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.PDF b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.PDF new file mode 100644 index 0000000..dd885da Binary files /dev/null and b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.PDF differ diff --git a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino new file mode 100644 index 0000000..b14da34 --- /dev/null +++ b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino @@ -0,0 +1,140 @@ +#define A_PIN 12 +#define B_PIN 13 +#define C_PIN 7 +#define D_PIN 8 +#define E_PIN 9 +#define F_PIN 11 +#define G_PIN 10 +#define DP_PIN 6 +#define EN0_PIN 5 +#define EN1_PIN 4 +#define EN2_PIN 3 +#define EN3_PIN 2 + +int print_dec(uint16_t value); +int print_digit(uint8_t position, uint8_t digit); +void timer_init(void); +void gpio_init(void); + +const uint8_t segm_pins[8] = {A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, F_PIN, G_PIN, DP_PIN}; +const uint8_t en_pins[4] = {EN0_PIN, EN1_PIN, EN2_PIN, EN3_PIN}; + +const uint8_t segment_map[16] = +{ + // A B C D E F G DP + 0b00000011, // 0 + 0b10011111, // 1 + 0b00100101, // 2 + 0b00001101, // 3 + 0b10011001, // 4 + 0b01001001, // 5 + 0b01000001, // 6 + 0b00011111, // 7 + 0b00000001, // 8 + 0b00001001, // 9 + 0b00010001, // A + 0b11000001, // b + 0b01100011, // C + 0b10000101, // d + 0b01100001, // E + 0b01110001 // F +}; + +volatile uint8_t display_value[4] = {0}; +volatile uint8_t current_digit = 0; + +void setup() +{ + gpio_init(); + timer_init(); +} + +void loop() +{ + for (uint16_t cnt = 9999; cnt > 0; cnt--) + { + print_dec(cnt); + delay(100); + } + delay(3000); +} + +int print_dec(uint16_t value) +{ + if (value > 9999) + { + return -1; + } + + for (uint8_t i = 0; i < 4; i++) + { + print_digit(3 - i, value % 10); + value /= 10; + } + + return 0; +} + +int print_digit(uint8_t position, uint8_t digit) +{ + if (position > 4 || digit > 15) + { + return -1; + } + + display_value[position] = digit; + + return 0; +} + +ISR(TIMER1_OVF_vect) +{ + digitalWrite(en_pins[current_digit], HIGH); + + current_digit++; + if (current_digit > 3) + { + current_digit = 0; + } + + for (uint8_t i = 0; i < 8; i++) + { + digitalWrite(segm_pins[i], segment_map[display_value[current_digit]] & (128 >> i)); + } + + digitalWrite(en_pins[current_digit], LOW); +} + +void gpio_init(void) +{ + uint8_t i; + for (i = 0; i < 4; i++) + { + pinMode(en_pins[i], OUTPUT); + digitalWrite(en_pins[i], HIGH); + } + for (i = 0; i < 8; i++) + { + pinMode(segm_pins[i], OUTPUT); + digitalWrite(segm_pins[i], HIGH); + } +} + +void timer_init(void) +{ + noInterrupts(); + + // After clearing TCCR1B the timer is stopped + TCCR1B = 0; + TCNT1 = 0; + + TCCR1A = (1 << WGM11); + TCCR1B |= (1 << WGM12) | (1 << WGM13); + TIMSK1 = (1 << TOIE1); + + // Set frequency to 1kHz + ICR1 = 1999; + TCCR1B |= (1 << CS11); + + interrupts(); +} diff --git a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj new file mode 100644 index 0000000..d482f6c Binary files /dev/null and b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj differ diff --git a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj.DESKTOP-DNPR54D.Cartogan.workspace b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj.DESKTOP-DNPR54D.Cartogan.workspace new file mode 100644 index 0000000..1c21abc --- /dev/null +++ b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj.DESKTOP-DNPR54D.Cartogan.workspace @@ -0,0 +1,101 @@ + + + + 2c0000000200000003000000ffffffffffffffffffffffffffffffffab0000000d000000d606000004040000 + + + + + + + + 542 + No + 100 + 120 + 100 + + + + + 83 + No + Yes + 83 + Yes + No + No + Yes + 0 + 83 + 100 + 83 + 0 + + + + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000100 + + + + + 2 + Yes + 2 + Yes + Yes + 00000020 + + + + + diff --git a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.png b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.png new file mode 100644 index 0000000..26fb620 Binary files /dev/null and b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.png differ diff --git a/Examples/7-segm_raw_dynamic_timer/Backup Of 7-segm_raw_dynamic_timer.pdsbak b/Examples/7-segm_raw_dynamic_timer/Backup Of 7-segm_raw_dynamic_timer.pdsbak new file mode 100644 index 0000000..9bed130 Binary files /dev/null and b/Examples/7-segm_raw_dynamic_timer/Backup Of 7-segm_raw_dynamic_timer.pdsbak differ diff --git a/Examples/7-segm_raw_dynamic_timer/Last Loaded 7-segm_raw_dynamic_timer.pdsbak b/Examples/7-segm_raw_dynamic_timer/Last Loaded 7-segm_raw_dynamic_timer.pdsbak new file mode 100644 index 0000000..8acc458 Binary files /dev/null and b/Examples/7-segm_raw_dynamic_timer/Last Loaded 7-segm_raw_dynamic_timer.pdsbak differ diff --git a/Examples/LCD_scroll/LCD_scroll.ino b/Examples/LCD_scroll/LCD_scroll.ino new file mode 100644 index 0000000..c84426d --- /dev/null +++ b/Examples/LCD_scroll/LCD_scroll.ino @@ -0,0 +1,98 @@ +/* + LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight() + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and uses the + scrollDisplayLeft() and scrollDisplayRight() methods to scroll + the text. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + modified 24 Feb 2021 + by Vladimir Garistov + + This example code is in the public domain. + + http://www.arduino.cc/en/Tutorial/LiquidCrystalScroll + +*/ + +#include + +#define RS 12 +#define EN 11 +#define D4 5 +#define D5 4 +#define D6 3 +#define D7 2 + +#define COLS 16 +#define ROWS 2 + +// initialize the library by associating any needed LCD interface pin +// with the arduino pin number it is connected to +LiquidCrystal lcd(RS, EN, D4, D5, D6, D7); + +void setup() +{ + // set up the LCD's number of columns and rows: + lcd.begin(COLS, ROWS); + lcd.print("hello, world!"); + delay(1000); +} + +void loop() +{ + // scroll 13 positions (string length) to the left + // to move it offscreen left: + for (uint8_t positionCounter = 0; positionCounter < 13; positionCounter++) + { + // scroll one position left: + lcd.scrollDisplayLeft(); + delay(150); + } + + // scroll 29 positions (string length + display length) to the right + // to move it offscreen right: + for (uint8_t positionCounter = 0; positionCounter < 29; positionCounter++) + { + // scroll one position right: + lcd.scrollDisplayRight(); + delay(150); + } + + // scroll 16 positions (display length + string length) to the left + // to move it back to center: + for (uint8_t positionCounter = 0; positionCounter < 16; positionCounter++) + { + // scroll one position left: + lcd.scrollDisplayLeft(); + delay(150); + } + + delay(1000); +} diff --git a/Examples/LCD_scroll/LCD_scroll.png b/Examples/LCD_scroll/LCD_scroll.png new file mode 100644 index 0000000..9d12da2 Binary files /dev/null and b/Examples/LCD_scroll/LCD_scroll.png differ diff --git a/LCD_layers.png b/LCD_layers.png new file mode 100644 index 0000000..b35d7b3 Binary files /dev/null and b/LCD_layers.png differ diff --git a/LCD_layers.svg b/LCD_layers.svg new file mode 100644 index 0000000..ac636af --- /dev/null +++ b/LCD_layers.svg @@ -0,0 +1,401 @@ + + + + + + + image/svg+xml + + + Layer of an LCD display + + + Ed Sanders + + + 1. Vertical filter film to polarize the light as it enters. +2. Glass substrate with ITO electrodes. The shapes of these electrodes will determine the dark shapes that will appear when the LCD is turned on. Vertical ridges are etched on the surface so the liquid crystals are in line with the polarized light. +3. Twisted nematic liquid crystals. +4. Glass substrate with common electrode film (ITO) with horizontal ridges to line up with the horizontal filter. +5. Horizontal filter film to block/allow through light. +6. Reflective surface to send light back to viewer. + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + 2 + 3 + 4 + 5 + 6 + + diff --git a/TN-LCD-schematic-MS-208kB.png b/TN-LCD-schematic-MS-208kB.png new file mode 100644 index 0000000..c15c1ff Binary files /dev/null and b/TN-LCD-schematic-MS-208kB.png differ