Merge pull request #2325 from opentx/jivarofad/M2560

LCD driver for stock and M2560
This commit is contained in:
Bertrand Songis
2015-05-21 19:07:01 +02:00
8 changed files with 190 additions and 130 deletions
+72 -60
View File
@@ -36,7 +36,7 @@ $Descr A4 11693 8268
encoding utf-8 encoding utf-8
Sheet 1 1 Sheet 1 1
Title "OpenTX board based on Arduino MEGA2560" Title "OpenTX board based on Arduino MEGA2560"
Date "14 feb 2015" Date "20 may 2015"
Rev "0" Rev "0"
Comp "Copyright 2015 F. Aguerre" Comp "Copyright 2015 F. Aguerre"
Comment1 "" Comment1 ""
@@ -196,10 +196,10 @@ F 3 "" H 8800 6900 60 0001 C CNN
1 0 0 -1 1 0 0 -1
$EndComp $EndComp
$Comp $Comp
L R R6 L R R7
U 1 1 54997DEC U 1 1 54997DEC
P 8800 6550 P 8800 6550
F 0 "R6" V 8880 6550 50 0000 C CNN F 0 "R7" V 8880 6550 50 0000 C CNN
F 1 "100K" V 8800 6550 50 0000 C CNN F 1 "100K" V 8800 6550 50 0000 C CNN
F 2 "" H 8800 6550 60 0001 C CNN F 2 "" H 8800 6550 60 0001 C CNN
F 3 "" H 8800 6550 60 0001 C CNN F 3 "" H 8800 6550 60 0001 C CNN
@@ -207,11 +207,11 @@ F 3 "" H 8800 6550 60 0001 C CNN
-1 0 0 1 -1 0 0 1
$EndComp $EndComp
$Comp $Comp
L R R6 L R R5
U 1 1 54997CFE U 1 1 54997CFE
P 7800 6000 P 7800 6000
F 0 "R6" V 7880 6000 50 0000 C CNN F 0 "R5" V 7880 6000 50 0000 C CNN
F 1 "100K" V 7800 6000 50 0000 C CNN F 1 "6.8K" V 7800 6000 50 0000 C CNN
F 2 "" H 7800 6000 60 0001 C CNN F 2 "" H 7800 6000 60 0001 C CNN
F 3 "" H 7800 6000 60 0001 C CNN F 3 "" H 7800 6000 60 0001 C CNN
1 7800 6000 1 7800 6000
@@ -310,11 +310,11 @@ F 3 "" H 9850 4600 60 0001 C CNN
0 1 -1 0 0 1 -1 0
$EndComp $EndComp
$Comp $Comp
L R R6 L R R5
U 1 1 5499427F U 1 1 5499427F
P 10100 4850 P 10100 4850
F 0 "R6" V 10180 4850 50 0000 C CNN F 0 "R5" V 10180 4850 50 0000 C CNN
F 1 "100K" V 10100 4850 50 0000 C CNN F 1 "6.8K" V 10100 4850 50 0000 C CNN
F 2 "" H 10100 4850 60 0001 C CNN F 2 "" H 10100 4850 60 0001 C CNN
F 3 "" H 10100 4850 60 0001 C CNN F 3 "" H 10100 4850 60 0001 C CNN
1 10100 4850 1 10100 4850
@@ -342,42 +342,42 @@ F 3 "" H 9100 4600 60 0001 C CNN
1 9100 4600 1 9100 4600
1 0 0 -1 1 0 0 -1
$EndComp $EndComp
Text Label 6450 3850 2 42 ~ 0 Text Label 6650 3900 2 42 ~ 0
U_batt U_batt
$Comp $Comp
L R R3 L R R3
U 1 1 54994034 U 1 1 54994034
P 6050 4100 P 6250 4150
F 0 "R3" V 6130 4100 50 0000 C CNN F 0 "R3" V 6330 4150 50 0000 C CNN
F 1 "2.7K" V 6050 4100 50 0000 C CNN F 1 "2.7K" V 6250 4150 50 0000 C CNN
F 2 "" H 6050 4100 60 0001 C CNN F 2 "" H 6250 4150 60 0001 C CNN
F 3 "" H 6050 4100 60 0001 C CNN F 3 "" H 6250 4150 60 0001 C CNN
1 6050 4100 1 6250 4150
-1 0 0 -1 -1 0 0 -1
$EndComp $EndComp
$Comp $Comp
L R R4 L R R4
U 1 1 54994033 U 1 1 54994033
P 5800 3850 P 6000 3900
F 0 "R4" V 5880 3850 50 0000 C CNN F 0 "R4" V 6080 3900 50 0000 C CNN
F 1 "5.1K" V 5800 3850 50 0000 C CNN F 1 "5.1K" V 6000 3900 50 0000 C CNN
F 2 "" H 5800 3850 60 0001 C CNN F 2 "" H 6000 3900 60 0001 C CNN
F 3 "" H 5800 3850 60 0001 C CNN F 3 "" H 6000 3900 60 0001 C CNN
1 5800 3850 1 6000 3900
0 1 -1 0 0 1 -1 0
$EndComp $EndComp
$Comp $Comp
L GND #PWR? L GND #PWR?
U 1 1 54994032 U 1 1 54994032
P 6050 4450 P 6250 4500
F 0 "#PWR?" H 6050 4450 30 0001 C CNN F 0 "#PWR?" H 6250 4500 30 0001 C CNN
F 1 "GND" H 6050 4380 30 0001 C CNN F 1 "GND" H 6250 4430 30 0001 C CNN
F 2 "" H 6050 4450 60 0001 C CNN F 2 "" H 6250 4500 60 0001 C CNN
F 3 "" H 6050 4450 60 0001 C CNN F 3 "" H 6250 4500 60 0001 C CNN
1 6050 4450 1 6250 4500
1 0 0 -1 1 0 0 -1
$EndComp $EndComp
Text Notes 5400 3500 0 60 ~ 0 Text Notes 5600 3550 0 60 ~ 0
Battery voltage reading Battery voltage reading
Text Notes 7250 1950 0 60 ~ 0 Text Notes 7250 1950 0 60 ~ 0
Rotary encoders (x2) Rotary encoders (x2)
@@ -461,11 +461,11 @@ F 3 "" H 5250 1000 60 0001 C CNN
1 0 0 -1 1 0 0 -1
$EndComp $EndComp
$Comp $Comp
L R R3 L R R2
U 1 1 54993A62 U 1 1 54993A62
P 5250 2200 P 5250 2200
F 0 "R3" V 5330 2200 50 0000 C CNN F 0 "R2" V 5330 2200 50 0000 C CNN
F 1 "2.7K" V 5250 2200 50 0000 C CNN F 1 "2.2K" V 5250 2200 50 0000 C CNN
F 2 "" H 5250 2200 60 0001 C CNN F 2 "" H 5250 2200 60 0001 C CNN
F 3 "" H 5250 2200 60 0001 C CNN F 3 "" H 5250 2200 60 0001 C CNN
1 5250 2200 1 5250 2200
@@ -646,10 +646,10 @@ $EndComp
Text Label 9250 1000 0 42 ~ 0 Text Label 9250 1000 0 42 ~ 0
M2560_Ouput M2560_Ouput
$Comp $Comp
L R R5 L R R6
U 1 1 54992F2E U 1 1 54992F2E
P 10250 1250 P 10250 1250
F 0 "R5" V 10330 1250 50 0000 C CNN F 0 "R6" V 10330 1250 50 0000 C CNN
F 1 "10K" V 10250 1250 50 0000 C CNN F 1 "10K" V 10250 1250 50 0000 C CNN
F 2 "" H 10250 1250 60 0001 C CNN F 2 "" H 10250 1250 60 0001 C CNN
F 3 "" H 10250 1250 60 0001 C CNN F 3 "" H 10250 1250 60 0001 C CNN
@@ -837,10 +837,10 @@ F 3 "" H 2350 2100 60 0001 C CNN
1 0 0 -1 1 0 0 -1
$EndComp $EndComp
$Comp $Comp
L R R5 L R R6
U 1 1 549891B4 U 1 1 549891B4
P 2150 1700 P 2150 1700
F 0 "R5" V 2230 1700 50 0000 C CNN F 0 "R6" V 2230 1700 50 0000 C CNN
F 1 "10K" V 2150 1700 50 0000 C CNN F 1 "10K" V 2150 1700 50 0000 C CNN
F 2 "" H 2150 1700 60 0001 C CNN F 2 "" H 2150 1700 60 0001 C CNN
F 3 "" H 2150 1700 60 0001 C CNN F 3 "" H 2150 1700 60 0001 C CNN
@@ -872,10 +872,10 @@ F 3 "" H 1400 2300 60 0001 C CNN
1 0 0 -1 1 0 0 -1
$EndComp $EndComp
$Comp $Comp
L R R5 L R R6
U 1 1 549891AC U 1 1 549891AC
P 2050 2800 P 2050 2800
F 0 "R5" V 2130 2800 50 0000 C CNN F 0 "R6" V 2130 2800 50 0000 C CNN
F 1 "10K" V 2050 2800 50 0000 C CNN F 1 "10K" V 2050 2800 50 0000 C CNN
F 2 "" H 2050 2800 60 0001 C CNN F 2 "" H 2050 2800 60 0001 C CNN
F 3 "" H 2050 2800 60 0001 C CNN F 3 "" H 2050 2800 60 0001 C CNN
@@ -998,10 +998,10 @@ F 3 "" H 9100 5400 60 0001 C CNN
0 1 -1 0 0 1 -1 0
$EndComp $EndComp
$Comp $Comp
L R R6 L R R7
U 1 1 549881D8 U 1 1 549881D8
P 8850 5600 P 8850 5600
F 0 "R6" V 8930 5600 50 0000 C CNN F 0 "R7" V 8930 5600 50 0000 C CNN
F 1 "100K" V 8850 5600 50 0000 C CNN F 1 "100K" V 8850 5600 50 0000 C CNN
F 2 "" H 8850 5600 60 0001 C CNN F 2 "" H 8850 5600 60 0001 C CNN
F 3 "" H 8850 5600 60 0001 C CNN F 3 "" H 8850 5600 60 0001 C CNN
@@ -40954,12 +40954,12 @@ $EndComp
$Comp $Comp
L +BATT U? L +BATT U?
U 1 1 549E8260 U 1 1 549E8260
P 5450 3750 P 5650 3800
F 0 "U?" H 5450 3700 60 0001 C CNN F 0 "U?" H 5650 3750 60 0001 C CNN
F 1 "+BATT" H 5450 3850 50 0000 C BNN F 1 "+BATT" H 5650 3900 50 0000 C BNN
F 2 "" H 5450 3750 60 0001 C CNN F 2 "" H 5650 3800 60 0001 C CNN
F 3 "" H 5450 3750 60 0001 C CNN F 3 "" H 5650 3800 60 0001 C CNN
1 5450 3750 1 5650 3800
1 0 0 -1 1 0 0 -1
$EndComp $EndComp
$Comp $Comp
@@ -41022,24 +41022,24 @@ F 3 "" H 10450 4200 60 0001 C CNN
1 0 0 -1 1 0 0 -1
$EndComp $EndComp
$Comp $Comp
L R R? L R R6
U 1 1 549E8FFF U 1 1 549E8FFF
P 10450 3850 P 10450 3850
F 0 "R?" V 10530 3850 50 0000 C CNN F 0 "R6" V 10530 3850 50 0000 C CNN
F 1 "10K" V 10450 3850 50 0000 C CNN F 1 "10K" V 10450 3850 50 0000 C CNN
F 2 "" H 10450 3850 60 0001 C CNN F 2 "" H 10450 3850 60 0001 C CNN
F 3 "" H 10450 3850 60 0001 C CNN F 3 "" H 10450 3850 60 0001 C CNN
1 10450 3850 1 10450 3850
-1 0 0 -1 -1 0 0 -1
$EndComp $EndComp
Text Label 6500 7150 2 42 ~ 0 Text Label 6550 7450 2 42 ~ 0
OpenTX I/O OpenTX output
Text GLabel 5250 7150 2 42 Output ~ 0 Text GLabel 5250 7450 2 42 Output ~ 0
port pin (initial state) port pin (initial state)
Text Notes 5500 7050 0 60 ~ 0 Text Notes 5450 7300 0 60 ~ 0
Caption Pinout caption :
Text Label 5550 2550 2 42 ~ 0 Text Label 5550 2550 2 42 ~ 0
Gain = 1 + R3/R6 Gain = 1 + R2/R6
$Bitmap $Bitmap
Pos 4600 4650 Pos 4600 4650
Scale 1.000000 Scale 1.000000
@@ -41200,7 +41200,7 @@ Wire Wire Line
Wire Wire Line Wire Wire Line
2400 1700 2500 1700 2400 1700 2500 1700
Wire Wire Line Wire Wire Line
6050 4350 6050 4450 6250 4400 6250 4500
Wire Wire Line Wire Wire Line
9600 2250 9450 2250 9600 2250 9450 2250
Wire Wire Line Wire Wire Line
@@ -41604,7 +41604,7 @@ Wire Wire Line
Wire Wire Line Wire Wire Line
10750 3800 10750 4200 10750 3800 10750 4200
Wire Wire Line Wire Wire Line
6450 3850 6050 3850 6650 3900 6250 3900
Wire Wire Line Wire Wire Line
1900 1450 1900 1700 1900 1450 1900 1700
Wire Wire Line Wire Wire Line
@@ -41642,9 +41642,9 @@ Wire Wire Line
Wire Wire Line Wire Wire Line
4400 1350 4850 1350 4400 1350 4850 1350
Wire Wire Line Wire Wire Line
5450 3750 5450 3850 5650 3800 5650 3900
Wire Wire Line Wire Wire Line
5450 3850 5550 3850 5650 3900 5750 3900
Wire Wire Line Wire Wire Line
7500 4600 8600 4600 7500 4600 8600 4600
Connection ~ 8300 4600 Connection ~ 8300 4600
@@ -41664,9 +41664,9 @@ Wire Wire Line
Wire Wire Line Wire Wire Line
10450 4100 10450 4200 10450 4100 10450 4200
Wire Wire Line Wire Wire Line
6050 7150 6500 7150 6050 7450 6550 7450
Wire Wire Line Wire Wire Line
5100 7150 5250 7150 5100 7450 5250 7450
Wire Wire Line Wire Wire Line
4700 4650 4700 4300 4700 4650 4700 4300
Wire Wire Line Wire Wire Line
@@ -41738,4 +41738,16 @@ F 3 "" H 1750 7050 60 0000 C CNN
1 1750 7050 1 1750 7050
-1 0 0 1 -1 0 0 1
$EndComp $EndComp
Text Notes 4850 6550 0 42 ~ 0
LCD supported : ST7565P, ST7565R, ERC12864FSF, ST7920\nProtocol = 6800, 8 bits parallel mode\n\nLCD pinout labels (may differ, depending of brand) :\nRD = Read or Enable on ST7920\nWR = WRite or Write(0)/Read(1) on ST7920\nA0 = R/S (register select) or D/I (data/instruction select)\nRST = RES (reset)\nCS = Chip Select (not used on ST7920)
Text Label 6550 7550 2 42 ~ 0
OpenTX input
Text GLabel 5250 7550 2 42 Input ~ 0
port pin (initial state)
Wire Wire Line
6050 7550 6550 7550
Wire Wire Line
5100 7550 5250 7550
Text Notes 2300 2950 0 60 ~ 0
NOTA : all features are optional !\nM2560 can properly work without switch deboucing,\nrotary encoder or PPM / power management.\nMinimum requirement is just LCD and navigation keys.\nSome switches could be usefull, especially for flight\nconditions, but not fundamental.
$EndSCHEMATC $EndSCHEMATC
Binary file not shown.
Binary file not shown.
Binary file not shown.
+13 -7
View File
@@ -57,6 +57,10 @@ PCB = 9X
# PCB revision # PCB revision
PCBREV = PCBREV =
# LCD
# Values: DEFAULT, ST7565P, ST7565R, ERC12864FSF, ST7920
LCD = DEFAULT
# Enable JETI-Telemetry or FrSky Telemetry reception on UART0 # Enable JETI-Telemetry or FrSky Telemetry reception on UART0
# For this option you need to modify your hardware! # For this option you need to modify your hardware!
# More information at [insertURLhere] # More information at [insertURLhere]
@@ -696,13 +700,7 @@ ifeq ($(PCB), MEGA2560)
BITMAPS += bitmaps/9X/splash.lbm bitmaps/9X/asterisk.lbm bitmaps/9X/about.lbm BITMAPS += bitmaps/9X/splash.lbm bitmaps/9X/asterisk.lbm bitmaps/9X/about.lbm
GUIGENERALSRC += gui/$(GUIDIRECTORY)/menu_general_diagkeys.cpp gui/$(GUIDIRECTORY)/menu_general_diaganas.cpp GUIGENERALSRC += gui/$(GUIDIRECTORY)/menu_general_diagkeys.cpp gui/$(GUIDIRECTORY)/menu_general_diaganas.cpp
# LCD driver EXTRABOARDSRC = targets/common_avr/adc_driver.cpp targets/stock/lcd_driver.cpp targets/common_avr/telemetry_driver.cpp
# Values: ST7565P(default), ST7565R
LCD = ST7565P
ifeq ($(LCD), ST7565R)
CPPDEFS += -DLCD_ST7565R
endif
EXTRABOARDSRC = targets/common_avr/adc_driver.cpp targets/stock/lcd_driver.cpp targets/common_avr/telemetry_driver.cpp
ifeq ($(SDCARD), YES) ifeq ($(SDCARD), YES)
EXTRABOARDSRC += $(FATFSDIR)/ff.c $(FATFSDIR)/fattime.c $(FATFSDIR)/option/ccsbcs.c targets/gruvin9x/diskio.cpp EXTRABOARDSRC += $(FATFSDIR)/ff.c $(FATFSDIR)/fattime.c $(FATFSDIR)/option/ccsbcs.c targets/gruvin9x/diskio.cpp
@@ -1087,6 +1085,14 @@ ifeq ($(TURNIGY_TRANSMITTER_FIX), YES)
endif endif
endif endif
ifeq ($(LCD), ST7565R)
CPPDEFS += -DLCD_ST7565R
else ifeq ($(LCD), ERC12864FSF)
CPPDEFS += -DLCD_ERC12864FSF
else ifeq ($(LCD), ST7920)
CPPDEFS += -DLCD_ST7920
endif
ifeq ($(AUTOSWITCH), YES) ifeq ($(AUTOSWITCH), YES)
CPPDEFS += -DAUTOSWITCH CPPDEFS += -DAUTOSWITCH
endif endif
@@ -48,7 +48,7 @@ inline void boardInit()
DDRE = 0b00000010; PORTE = 0b11111100; // 7:N/A, 6:N/A, 5:RENC1_B, 4:RENC1_A, 3:N/A, 2:N/A, 1:TELEM_TX, 0:TELEM_RX DDRE = 0b00000010; PORTE = 0b11111100; // 7:N/A, 6:N/A, 5:RENC1_B, 4:RENC1_A, 3:N/A, 2:N/A, 1:TELEM_TX, 0:TELEM_RX
DDRF = 0b00000000; PORTF = 0b11111111; // 7-0:Trim switch inputs DDRF = 0b00000000; PORTF = 0b11111111; // 7-0:Trim switch inputs
DDRG = 0b00000000; PORTG = 0b11111111; // 7:N/A, 6:N/A, 5:N/A, 4:N/A, 3:N/A, 2:TCut_SW, 1:Gear_SW, 0: RudDr_SW DDRG = 0b00000000; PORTG = 0b11111111; // 7:N/A, 6:N/A, 5:N/A, 4:N/A, 3:N/A, 2:TCut_SW, 1:Gear_SW, 0: RudDr_SW
DDRH = 0b00011000; PORTH = 0b11110110; // 7:N/A, 6:RFPw, 5:JackPres, 4:HoldPw, 3:Speaker, 2:N/A, 1:N/A, 0:Haptic DDRH = 0b00011000; PORTH = 0b11110110; // 7:N/A, 6:RF_Activated, 5:DSC_Activated, 4:Hold_Pwower, 3:Speaker, 2:N/A, 1:N/A, 0:Haptic
DDRJ = 0b00000000; PORTJ = 0b11111111; // 7:N/A, 6:N/A, 5:N/A, 4:N/A, 3:N/A, 2:N/A, 1:RENC2_push, 0:RENC1_push DDRJ = 0b00000000; PORTJ = 0b11111111; // 7:N/A, 6:N/A, 5:N/A, 4:N/A, 3:N/A, 2:N/A, 1:RENC2_push, 0:RENC1_push
DDRK = 0b00000000; PORTK = 0b00000000; // Analogic input (no pull-ups) DDRK = 0b00000000; PORTK = 0b00000000; // Analogic input (no pull-ups)
DDRL = 0b00000000; PORTL = 0b11111111; // 7:TRN_SW 6:EleDR_SW, 5:ESC, 4:MENU 3:Keyb_Left, 2:Keyb_Right, 1:Keyb_Up, 0:Keyb_Down DDRL = 0b00000000; PORTL = 0b11111111; // 7:TRN_SW 6:EleDR_SW, 5:ESC, 4:MENU 3:Keyb_Left, 2:Keyb_Right, 1:Keyb_Up, 0:Keyb_Down
@@ -98,7 +98,7 @@ uint8_t pwrCheck()
void pwrOff() void pwrOff()
{ {
PORTH = 0xEF; // PortH-4 set to 0 PORTH &= ~0x10; // PortH-4 set to 0
} }
FORCEINLINE uint8_t keyDown() FORCEINLINE uint8_t keyDown()
+4 -4
View File
@@ -79,7 +79,7 @@
#define PAUSE_PPMIN_INTERRUPT() TIMSK3 &= ~(1<<ICIE3) #define PAUSE_PPMIN_INTERRUPT() TIMSK3 &= ~(1<<ICIE3)
#define RESUME_PPMIN_INTERRUPT() TIMSK3 |= (1<<ICIE3) #define RESUME_PPMIN_INTERRUPT() TIMSK3 |= (1<<ICIE3)
#define SLAVE_MODE() ~PINH & (1<<INP_H_RF_POW) #define SLAVE_MODE() ~PINH & (1<<INP_H_RF_Activated)
#define JACK_PPM_OUT() PORTB |= (1<<OUT_B_SIM_CTL) #define JACK_PPM_OUT() PORTB |= (1<<OUT_B_SIM_CTL)
#define JACK_PPM_IN() PORTB &= ~(1<<OUT_B_SIM_CTL) #define JACK_PPM_IN() PORTB &= ~(1<<OUT_B_SIM_CTL)
#define __BACKLIGHT_ON PORTC |= (1<<OUT_C_LIGHT) #define __BACKLIGHT_ON PORTC |= (1<<OUT_C_LIGHT)
@@ -133,9 +133,9 @@ void sdPoll10ms(void);
# define INP_D_I2C_SDA 0 # define INP_D_I2C_SDA 0
# define INP_E_TELEM_RX 1 # define INP_E_TELEM_RX 1
# define OUT_E_TELEM_TX 0 # define OUT_E_TELEM_TX 0
# define INP_H_RF_POW 6 # define INP_H_RF_Activated 6
//#define INP_H_ 5 //reserved JACKPRES //#define INP_H_ 5 //reserved DSC_Activated, for pwrCheck()
//#define INP_H_ 4 //reserved HOLDPWR //#define INP_H_ 4 //reserved Hold_Power, for pwrCheck()
# define OUT_H_Speaker 3 # define OUT_H_Speaker 3
# define OUT_H_HAPTIC 0 # define OUT_H_HAPTIC 0
+99 -57
View File
@@ -36,18 +36,11 @@
#include "opentx.h" #include "opentx.h"
#define delay_1us() _delay_us(1)
#define delay_2us() _delay_us(2)
void delay_1_5us(uint16_t ms)
{
for (uint16_t i=0; i<ms; i++) delay_1us();
}
void lcdSendCtl(uint8_t val) void lcdSendCtl(uint8_t val)
{ {
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_CS1); PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_CS1);
#ifdef LCD_MULTIPLEX #ifdef LCD_MULTIPLEX
DDRA = 0xFF; // set LCD_DAT pins to output DDRA = 0xFF; //Set LCD_DAT pins to output
#endif #endif
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_A0); PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_A0);
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RnW); PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RnW);
@@ -56,7 +49,7 @@ void lcdSendCtl(uint8_t val)
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_E); PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_E);
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0); PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0);
#ifdef LCD_MULTIPLEX #ifdef LCD_MULTIPLEX
DDRA = 0x00; // set LCD_DAT pins to input DDRA = 0x00; //Set LCD_DAT pins to input
#endif #endif
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_CS1); PORTC_LCD_CTRL |= (1<<OUT_C_LCD_CS1);
} }
@@ -72,10 +65,11 @@ volatile uint8_t LcdLock ;
const static pm_uchar lcdInitSequence[] PROGMEM = const static pm_uchar lcdInitSequence[] PROGMEM =
{ {
#ifdef LCD_ST7565R //ST7565 eq. : KS0713, SED1565, S6B1713, SPLC501C, NT7532 /34 /38, TL03245
#if defined(LCD_ST7565R)
0xE2, //Initialize the internal functions 0xE2, //Initialize the internal functions
0xAE, //DON = 0: display OFF 0xAE, //DON = 0: display OFF
0xA0, //ADC = 0: normal direction(SEG132->SEG1) 0xA0, //ADC = 0: normal direction (SEG132->SEG1)
0xA6, //REV = 0: non-reverse display 0xA6, //REV = 0: non-reverse display
0xA4, //EON = 0: normal display. non-entire 0xA4, //EON = 0: normal display. non-entire
0xA2, //Select LCD bias 0xA2, //Select LCD bias
@@ -85,11 +79,11 @@ const static pm_uchar lcdInitSequence[] PROGMEM =
0x81, //Set reference voltage Mode 0x81, //Set reference voltage Mode
0x22, //24 SV5 SV4 SV3 SV2 SV1 SV0 = 0x18 0x22, //24 SV5 SV4 SV3 SV2 SV1 SV0 = 0x18
0xAF, //DON = 1: display ON 0xAF, //DON = 1: display ON
0x60 //sets the display start line to zero 0x60 //Set the display start line to zero
#elif LCD_ERC12864FSF #elif defined(LCD_ERC12864FSF)
0xE2, //Initialize the internal functions 0xE2, //Initialize the internal functions
0xAE, //DON = 0: display OFF 0xAE, //DON = 0: display OFF
0xA1, //ADC = 1: reverse direction(SEG132->SEG1) 0xA1, //ADC = 1: reverse direction (SEG132->SEG1)
0xA6, //REV = 0: non-reverse display 0xA6, //REV = 0: non-reverse display
0xA4, //EON = 0: normal display. non-entire 0xA4, //EON = 0: normal display. non-entire
0xA3, //Select LCD bias 0xA3, //Select LCD bias
@@ -99,7 +93,13 @@ const static pm_uchar lcdInitSequence[] PROGMEM =
0x81, //Set reference voltage Mode 0x81, //Set reference voltage Mode
0x2D, //24 SV5 SV4 SV3 SV2 SV1 SV0 0x2D, //24 SV5 SV4 SV3 SV2 SV1 SV0
0xAF //DON = 1: display ON 0xAF //DON = 1: display ON
#else #elif defined(LCD_ST7920)
0x30, //Set 8-bit interface
0x36, //Repeat with graphics bit set to ON
0x0C, //Display ON, cursor and blink OFF
0x01, //Clear display, reset address
0x06 //Display ON, no cursor
#else //ST7565P (default 9x LCD)
0xE2, //Initialize the internal functions 0xE2, //Initialize the internal functions
0xAE, //DON = 0: display OFF 0xAE, //DON = 0: display OFF
0xA1, //ADC = 1: reverse direction(SEG132->SEG1) 0xA1, //ADC = 1: reverse direction(SEG132->SEG1)
@@ -117,62 +117,104 @@ const static pm_uchar lcdInitSequence[] PROGMEM =
inline void lcdInit() inline void lcdInit()
{ {
// /home/thus/txt/datasheets/lcd/KS0713.pdf
// ~/txt/flieger/ST7565RV17.pdf from http://www.glyn.de/content.asp?wdid=132&sid=
LCD_LOCK(); LCD_LOCK();
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RES); //LCD_RES PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RES); //LCD reset
delay_2us(); _delay_us(2);
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_RES); // f524 sbi 0x15, 2 IOADR-PORTC_LCD_CTRL; 21 1 PORTC_LCD_CTRL |= (1<<OUT_C_LCD_RES); //LCD normal operation
delay_1_5us(1500); #ifdef LCD_ST7920
_delay_ms(40);
#else
_delay_us(1500);
#endif
for (uint8_t i=0; i<DIM(lcdInitSequence); i++) { for (uint8_t i=0; i<DIM(lcdInitSequence); i++) {
lcdSendCtl(pgm_read_byte(&lcdInitSequence[i])) ; lcdSendCtl(pgm_read_byte(&lcdInitSequence[i])) ;
#ifdef LCD_ST7920
_delay_us(80);
#endif
} }
#ifdef LCD_ERC12864FSF #ifdef LCD_ERC12864FSF
g_eeGeneral.contrast = 0x2D; g_eeGeneral.contrast = 0x2D;
#else #else
g_eeGeneral.contrast = 0x22; g_eeGeneral.contrast = 0x22;
#endif #endif
LCD_UNLOCK(); LCD_UNLOCK();
} }
void lcdSetRefVolt(uint8_t val) void lcdSetRefVolt(uint8_t val)
{ {
LCD_LOCK(); #ifndef LCD_ST7920 //No contrast setting for ST7920
lcdSendCtl(0x81); LCD_LOCK();
lcdSendCtl(val); lcdSendCtl(0x81);
LCD_UNLOCK(); lcdSendCtl(val);
LCD_UNLOCK();
#endif
} }
void lcdRefresh() void lcdRefresh()
{ {
LCD_LOCK(); LCD_LOCK();
#ifdef LCD_ST7920
uint8_t x_addr = 0;
uint8_t y_addr = 0;
uint16_t line_offset = 0;
uint8_t col_offset = 0;
uint16_t byte_offset = 0;
uint8_t bit_count = 0;
for(uint8_t y=0; y < 64; y++) {
x_addr = 0;
//Convert coordinates to weirdly-arranged 128x64 screen (the ST7920 is mapped for 256x32 displays)
if (y > 31)
{
y_addr = y - 32; //Because there are only 31 addressable lines in the ST7920
x_addr += 8; //so we overflow x (7 visible bytes per line) to reach the bottom half
}else{
y_addr = y;
}
lcdSendCtl( 0x80 | y_addr ); //Set Vertical Address
_delay_us(49);
lcdSendCtl( 0x80 | x_addr ); //Set Horizontal Address
_delay_us(49);
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0); //HIGH RS and LOW RW will put the LCD to
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RnW); //Write data register mode
bit_count = y & 0x07; //Count from 0 bis 7 -> 0=0, 1=1..7=7, 8=0, 9=1...
col_offset = 1 << bit_count; //Build a value for a AND operation with the vorrect bitposition
line_offset = ( y / 8 ) * 128; //On the ST7565 there are 8 lines with each 128 bytes width
for (coord_t x=0; x < 16; x++) { //Walk through 16 bytes form left to right (128 Pixel)
byte_offset = line_offset + ( x * 8 ); //Calculate the position of the first byte im array
//adressing the bytes sequential and shift the bits at the correct position, afterwards a OR operation to get all bits in one byte
//the position of the LSB is the left-most position of the byte to the ST7920
PORTA_LCD_DAT = (((displayBuf[byte_offset] & col_offset) >> bit_count) << 7) | (((displayBuf[byte_offset + 1] & col_offset) >> bit_count) << 6) | (((displayBuf[byte_offset + 2] & col_offset) >> bit_count ) << 5) | (((displayBuf[byte_offset + 3] & col_offset) >> bit_count ) << 4) | (((displayBuf[byte_offset + 4] & col_offset) >> bit_count ) << 3) | (((displayBuf[byte_offset + 5] & col_offset) >> bit_count ) << 2) | (((displayBuf[byte_offset + 6] & col_offset) >> bit_count ) << 1) | (((displayBuf[byte_offset + 7] & col_offset) >> bit_count ) << 0);
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_E);
_delay_us(8);
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_E);
_delay_us(49);
}
}
#else //All other LCD
uint8_t *p=displayBuf; uint8_t *p=displayBuf;
for(uint8_t y=0; y < 8; y++) { for(uint8_t y=0; y < 8; y++) {
#ifdef LCD_ST7565R
#ifdef LCD_ST7565R lcdSendCtl(0x01);
lcdSendCtl(0x01); #else
#else lcdSendCtl(0x04);
lcdSendCtl(0x04); #endif
#endif lcdSendCtl(0x10); //Column addr 0
lcdSendCtl( y | 0xB0); //Page addr y
lcdSendCtl(0x10); //column addr 0 PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_CS1);
lcdSendCtl( y | 0xB0); //page addr y #ifdef LCD_MULTIPLEX
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_CS1); DDRA = 0xFF; //Set LCD_DAT pins to output
#ifdef LCD_MULTIPLEX #endif
DDRA = 0xFF; // set LCD_DAT pins to output PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0);
#endif PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RnW);
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0); for (coord_t x=LCD_W; x>0; --x) {
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RnW); PORTA_LCD_DAT = *p++;
for (coord_t x=LCD_W; x>0; --x) { PORTC_LCD_CTRL |= (1<<OUT_C_LCD_E);
PORTA_LCD_DAT = *p++; PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_E);
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_E); }
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_E); PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0);
} PORTC_LCD_CTRL |= (1<<OUT_C_LCD_CS1);
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0);
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_CS1);
} }
#endif
LCD_UNLOCK(); LCD_UNLOCK();
} }