ATMega32 + 16MHz Quarz + LCD Display

  • C

Es gibt 3 Antworten in diesem Thema. Der letzte Beitrag () ist von Luca.

    ATMega32 + 16MHz Quarz + LCD Display

    Hi,
    ich habe ein kleines Problem. Mein Chip funktioniert mit einem LCD Display, aber wenn ich ein 16MHz Quarz verwende, überträgt der Chip nur die Hälfte an das Display. Jedes Mal steht etwas anderes auf dem Display, aber nicht das was das stehen soll. Da es mit 1MHz internem Quarz geht, weiß ich, dass das eigentlich richtig verkabelt und richtig programmiert ist. F_CPU hab ich nicht vergessen :D . Muss ich das Display irgendwie anders einstellen?

    Ich hoffe ihr könnt mir Helfen :D
    MfG Luca

    simpelSoft schrieb:

    2x22pF Kondensatoren nicht vergessen?

    Ne, hab ich nicht vergessen :D .

    simpelSoft schrieb:

    Fuse Bits richtig eingestellt?

    Glaub schon... Momentan benutze ich:
    High: 0x89
    Low: 0xCF

    Thunderbolt schrieb:

    Benutzt du das Display im 4-Bit-Modus

    Ich habe ein 8-Bit Display an Port A.

    Thunderbolt schrieb:

    Sind evtl. Datenleitungen vertauscht?

    Nein, mit dem interen Quarz geht alles Perfekt...
    puu.sh/iDHUj/26b9416fa4.jpg

    Edit: Ext. Quarz: puu.sh/iDHVb/b119a11d6c.jpg

    Mein Code (99% von hier: newbiehack.com/Microcontroller…ssingaStringtotheLCD.aspx) :

    Spoiler anzeigen
    lcd.h

    C-Quellcode

    1. #ifndef LCD_H_
    2. #define LCD_H_
    3. #ifndef F_CPU
    4. #warning "F_CPU not defined..."
    5. #define F_CPU 1000000UL
    6. #endif
    7. #include <avr/io.h>
    8. #include <util/delay.h>
    9. #include <stdlib.h>
    10. #define LCDCrib PORTA
    11. #define DataDir_LCDCrib DDRA
    12. #define LCDControl PORTD
    13. #define DataDir_LCDControl DDRD
    14. #define LightSwitch 5
    15. #define ReadWrite 7
    16. #define BiPolarMood 2
    17. char firstColumnPositions[4] = {0, 64, 20, 84};
    18. void Check_IF_LCD_isBusy(void);
    19. void Peek_A_Boo(void);
    20. void Send_A_Command(unsigned char command);
    21. void Send_A_Character(unsigned char character);
    22. void Send_A_String(char *StringOfCharacters);
    23. void GotoLCDLocation(uint8_t x, uint8_t y);
    24. void InitializeLCD(void);
    25. void Check_IF_LCD_isBusy()
    26. {
    27. DataDir_LCDCrib = 0;
    28. LCDControl |= 1<<ReadWrite;
    29. LCDControl &= ~1<<BiPolarMood;
    30. while (LCDCrib >= 0x80)
    31. {
    32. Peek_A_Boo();
    33. }
    34. DataDir_LCDCrib = 0xFF; //0xFF means 0b11111111
    35. }
    36. void Peek_A_Boo()
    37. {
    38. LCDControl |= 1<<LightSwitch;
    39. asm volatile ("nop");
    40. asm volatile ("nop");
    41. LCDControl &= ~1<<LightSwitch;
    42. }
    43. void Send_A_Command(unsigned char command)
    44. {
    45. Check_IF_LCD_isBusy();
    46. LCDCrib = command;
    47. LCDControl &= ~ ((1<<ReadWrite)|(1<<BiPolarMood));
    48. Peek_A_Boo();
    49. LCDCrib = 0;
    50. }
    51. void Send_A_Character(unsigned char character)
    52. {
    53. Check_IF_LCD_isBusy();
    54. LCDCrib = character;
    55. LCDControl &= ~ (1<<ReadWrite);
    56. LCDControl |= 1<<BiPolarMood;
    57. Peek_A_Boo();
    58. LCDCrib = 0;
    59. }
    60. void Send_A_String(char *StringOfCharacters)
    61. {
    62. while(*StringOfCharacters > 0)
    63. {
    64. Send_A_Character(*StringOfCharacters++);
    65. }
    66. }
    67. void GotoLCDLocation(uint8_t x, uint8_t y)
    68. {
    69. Send_A_Command(0x80 + firstColumnPositions[y] + (x));
    70. }
    71. void InitializeLCD()
    72. {
    73. DataDir_LCDControl |= 1<<LightSwitch | 1<<ReadWrite | 1<<BiPolarMood;
    74. _delay_ms(15);
    75. Send_A_Command(0x01); //Clear Screen 0x01 = 00000001
    76. _delay_ms(2);
    77. Send_A_Command(0x38);
    78. _delay_us(50);
    79. Send_A_Command(0b00001110);
    80. _delay_us(50);
    81. }
    82. #endif /* LCD_H_ */

    main.c

    C-Quellcode

    1. #define F_CPU 16000000UL
    2. #define BAUD 9600UL
    3. #include "lcd.h"
    4. #include "uart.h"
    5. #include <avr/io.h>
    6. #include <util/delay.h>
    7. int main(void)
    8. {
    9. InitializeLCD();
    10. GotoLCDLocation(5, 0);
    11. Send_A_String("Hallo Welt!");
    12. GotoLCDLocation(1, 1);
    13. Send_A_String("Das ist ein Test...");
    14. while(1)
    15. {
    16. GotoLCDLocation(1, 1);
    17. Send_A_String("Das ist ein Test...");
    18. _delay_ms(1000); // immer ein anderes ergebnis...
    19. }
    20. }



    Edit2: Hab den Fehler gefunden :D
    Der Chip ist eine ganze Millisekunde zu schnell:

    C-Quellcode

    1. void Check_IF_LCD_isBusy()
    2. {
    3. DataDir_LCDCrib = 0;
    4. LCDControl |= 1<<ReadWrite;
    5. _delay_ms(1); //mein Fehler
    6. LCDControl &= ~1<<BiPolarMood;
    7. while (LCDCrib >= 0x80)
    8. {
    9. Peek_A_Boo();
    10. }
    11. DataDir_LCDCrib = 0xFF; //0xFF means 0b11111111
    12. }


    Sry das ich das Thema gemacht hab und nicht richtig vorher gegooglet hab :D (hab ich hier gelesen falls es jemanden interessiert: roboternetz.de/community/threa…en-Quarz-nur-Hieroglyphen)

    Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von „Luca“ ()