alx1234
Newbie
I have three problems that I need to fix, please advise me what to do:
[code tags added by moderator]
- when i try to output the characters, some characters are display correctly and others are not
- when i send characters to the display, it iterates in chip 1 and after that in chip 2. In this Case it shows only on chip 1
- the down half of the display is offmy code
Code:
#include "modul-Display-hardware.h"
#include "font5x8.h" // Include font5x8.h
#include <avr/io.h>
#include <avr/pgmspace.h> // Für den Zugriff auf PROGMEM
#include <util/delay.h>
#define GLCD_RESET_PIN PD0
#define GLCD_RESET_PORT PORTD
#define GLCD_RESET_DDR DDRD
void glcd_reset_pin_init(void) {
// Set the reset pin as an output
GLCD_RESET_DDR |= (1 << GLCD_RESET_PIN);
// Start with the display not in reset
GLCD_RESET_PORT |= (1 << GLCD_RESET_PIN);
}
void glcd_reset(void) {
// Set the reset pin low to reset the GLCD
GLCD_RESET_PORT &= ~(1 << GLCD_RESET_PIN);
// Wait for at least 1ms
_delay_ms(1);
// Set the reset pin high to end the reset
GLCD_RESET_PORT |= (1 << GLCD_RESET_PIN);
// Wait for GLCD to be ready (specify time as per datasheet)
_delay_ms(10);
}
uint8_t modul_display_init(void){
// Initialisierungscode...
DDRA = 0xFF; // Alle Ports von Port A als Ausgang
DDRC |= (1 << DDC2);
DDRC |= (1 << DDC3);
DDRC |= (1 << DDC4);
DDRC |= (1 << DDC5);
DDRC |= (1 << DDC6);// Konfiguriere bestimmte Pins von Port C als Ausgang
DDRC |= (1 << DDC7);
PORTC = (1 << PORTC7);
modul_display_sendInstruction(63); // Display on
modul_display_sendInstruction(192); // Display Start Line
modul_display_sendInstruction(184); // Set Page (x 0-7)
modul_display_sendInstruction(64); // Set Address(y 0-63)
return 0;
}
void modul_display_sendInstruction(uint8_t data){
//uint8_t ready = modul_display_busyCheck(void);
//if(ready==0){
PORTA = data; // Daten an Port A senden
PORTC &= ~((1 << PC2) | (1 << PC3)); // D/I und R/W auf Low setzen
PORTC |= (1 << PC4); // Enable High
PORTC &= ~(1 << PC4); // Enable Low
//}
}
void modul_display_selectChip(bool chip){
if(chip){
PORTC = (PORTC & ~(1 << PC5)) | (1 << PC6); // CS2 high, CS1 low
} else {
PORTC = (PORTC & ~(1 << PC6)) | (1 << PC5); // CS1 high, CS2 low
}
}
void modul_display_writeDisplay(bool chip, uint8_t data){
modul_display_selectChip(chip);
modul_display_sendInstruction(184);
PORTA = data; // Daten an Port A senden
PORTC |= (1 << PC2); // D/I high
PORTC &= ~(1 << PC3); // R/W low
PORTC |= (1 << PC4); // Enable High
PORTC &= ~(1 << PC4); // Enable Low
}
//reset auf 1 und für enable auf start auf 1 und dann auf flanke
void modul_display_clearDisplay(){
for (uint8_t page = 0; page < 8; ++page) { // For each page
modul_display_sendInstruction(0xB0 | page); // Set page address (might be different for your display)
for (uint8_t chip = 0; chip < 2; ++chip) { // For each chip
modul_display_selectChip(chip);
for (uint8_t col = 0; col < 64; ++col) { // Assuming 64 columns per chip
// Write zero to clear the display
modul_display_writeDisplay(chip, 0x00);
}
}
}
}
void modul_display_showText(unsigned char *arr, uint16_t length, uint8_t page, uint8_t column) {
modul_display_sendInstruction(0xB0 | page); // Set page address
modul_display_sendInstruction(0x00 | (column & 0x0F)); // Set lower column address
modul_display_sendInstruction(0x10 | ((column >> 4) & 0x0F)); // Set higher column address
for (uint16_t i = 0; i < length; ++i) {
uint8_t ascii_index = arr;
uint8_t font_index = (ascii_index - 32) * 5; // Annahme: ASCII-Wert 32 ist der Start
for (uint8_t j = 0; j < 5; j++) {
modul_display_writeDisplay(true, pgm_read_byte(&font5x8[font_index + j]));
}
// Optional: Senden Sie hier ein zusätzliches leeres Byte für den Abstand zwischen den Zeichen
modul_display_writeDisplay(true, 0);
}
}
void modul_display_showCharArray(unsigned char *arr, uint16_t length){
for (uint16_t i = 0; i < length; ++i) {
uint8_t ascii_index = arr;
uint8_t font_index = (ascii_index - 32) * 5; // Annahme: ASCII-Wert 32 ist der Start
for(uint8_t j = 0; j < 5; j++) {
modul_display_writeDisplay(true, pgm_read_byte(&font5x8[font_index + j]));
}
// Optional: Senden Sie hier ein zusätzliches leeres Byte für den Abstand zwischen den Zeichen
modul_display_writeDisplay(true, 0);
}
}
uint8_t modul_display_run(void){
glcd_reset_pin_init();
glcd_reset();
// Definieren Sie ein Array von Zeichen, die angezeigt werden sollen
// ASCII-Werte für 'D', 'E', 'U'
unsigned char charactersToShow[] = {65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,};
// Initialisieren Sie das Display
modul_display_init();
_delay_ms(500);
//unsigned char textToShow[] = "Hello";
// Löschen Sie das Display, bevor Sie etwas Neues anzeigen
modul_display_clearDisplay();
//_delay_ms(500);
// Zeigen Sie die Zeichen auf dem Display an
modul_display_showCharArray(charactersToShow, 26);
//modul_display_showText(textToShow, 5, 0, 0);
return 0;
}
Last edited by a moderator: