• We recently switched our forum platform. If you experience any issues please email support@crystalfontz.com

CFAG12864B Code using C language

franklee

New member
I have been working on interfacing a CFAG12864B-YYH-V to an Atmel AVR microcontroller but have been having some problems. Has anyone got a sample of code using C language that they would be willing to share?

Thanks in advance,

Frank
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

franklee

New member
cfag12864 font chart/file wanted

I displayed a few chars on my display but cant believe I have to actually fill out hundreds of statements to make a complete font chart. Hasn't this wheel been invented already? I hope I overlooked something and there is an easier way.
 

CF Tech

Administrator
Here is an 8x8 font I have used:
08x08fnt.h
Code:
//Base character is: 32 = 0x20 = " "
#define FONT_08X08_BASE 32
extern prog_uchar Font_08x08[96][8];
08x08fnt.c
Code:
//============================================================================
// Crystalfontz demonstration code
// 08X08FNT.C: Bitmapped Font
// Samsung KS0107+KS0108 (S6B0107+S6B0108) LCD Controller
// Atmel ATMega32 processor @ 16MHz
// WinAVR / AVR GCC + Atmel AVR Studio
// Written by Brent A. Crosby
// Copyright 2005, Crystalfontz America, Inc. http://www.crystalfontz.com
//============================================================================
#include <avr/pgmspace.h>
#include "typedefs.h"
#include "08x08fnt.h"
prog_uchar Font_08x08[96][8]=
  {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //  32 = 0x20 = " "
   {0x00,0x00,0x06,0x5F,0x5F,0x06,0x00,0x00}, //  33 = 0x21 = "!"
   {0x00,0x07,0x07,0x00,0x07,0x07,0x00,0x00}, //  34 = 0x22 = """
   {0x14,0x7F,0x7F,0x14,0x7F,0x7F,0x14,0x00}, //  35 = 0x23 = "#"
   {0x24,0x2E,0x2A,0x6B,0x6B,0x3A,0x12,0x00}, //  36 = 0x24 = "$"
   {0x42,0x62,0x30,0x18,0x0C,0x46,0x42,0x00}, //  37 = 0x25 = "%"
   {0x30,0x7A,0x4F,0x4D,0x37,0x7A,0x48,0x00}, //  38 = 0x26 = "&"
   {0x00,0x00,0x04,0x07,0x03,0x00,0x00,0x00}, //  39 = 0x27 = "'"
   {0x00,0x1C,0x3E,0x63,0x41,0x00,0x00,0x00}, //  40 = 0x28 = "("
   {0x00,0x41,0x63,0x3E,0x1C,0x00,0x00,0x00}, //  41 = 0x29 = ")"
   {0x2A,0x3E,0x3E,0x1C,0x3E,0x3E,0x2A,0x00}, //  42 = 0x2A = "*"
   {0x00,0x08,0x08,0x3E,0x3E,0x08,0x08,0x00}, //  43 = 0x2B = "+"
   {0x00,0x00,0x40,0x70,0x30,0x00,0x00,0x00}, //  44 = 0x2C = ","
   {0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00}, //  45 = 0x2D = "-"
   {0x00,0x00,0x60,0x60,0x60,0x00,0x00,0x00}, //  46 = 0x2E = "."
   {0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00}, //  47 = 0x2F = "/"
   {0x3E,0x7F,0x71,0x59,0x4D,0x7F,0x3E,0x00}, //  48 = 0x30 = "0"
   {0x00,0x42,0x42,0x7F,0x7F,0x40,0x40,0x00}, //  49 = 0x31 = "1"
   {0x42,0x63,0x71,0x59,0x4D,0x67,0x62,0x00}, //  50 = 0x32 = "2"
   {0x22,0x63,0x49,0x49,0x49,0x7F,0x36,0x00}, //  51 = 0x33 = "3"
   {0x10,0x18,0x1C,0x16,0x7F,0x7F,0x10,0x00}, //  52 = 0x34 = "4"
   {0x27,0x67,0x45,0x45,0x45,0x7D,0x39,0x00}, //  53 = 0x35 = "5"
   {0x3E,0x7F,0x49,0x49,0x49,0x7B,0x32,0x00}, //  54 = 0x36 = "6"
   {0x03,0x03,0x01,0x71,0x79,0x0F,0x07,0x00}, //  55 = 0x37 = "7"
   {0x36,0x7F,0x49,0x49,0x49,0x7F,0x36,0x00}, //  56 = 0x38 = "8"
   {0x26,0x6F,0x49,0x49,0x49,0x7F,0x3E,0x00}, //  57 = 0x39 = "9"
   {0x00,0x00,0x00,0x66,0x66,0x66,0x00,0x00}, //  58 = 0x3A = ":"
   {0x00,0x00,0x80,0xE6,0x66,0x00,0x00,0x00}, //  59 = 0x3B = ";"
   {0x00,0x08,0x1C,0x36,0x63,0x41,0x00,0x00}, //  60 = 0x3C = "<"
   {0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x00}, //  61 = 0x3D = "="
   {0x00,0x41,0x63,0x36,0x1C,0x08,0x00,0x00}, //  62 = 0x3E = ">"
   {0x02,0x03,0x01,0x51,0x59,0x0F,0x06,0x00}, //  63 = 0x3F = "?"
   {0x3E,0x7F,0x41,0x59,0x59,0x5F,0x4E,0x00}, //  64 = 0x40 = "@"
   {0x7C,0x7E,0x13,0x11,0x13,0x7E,0x7C,0x00}, //  65 = 0x41 = "A"
   {0x41,0x7F,0x7F,0x49,0x49,0x7F,0x36,0x00}, //  66 = 0x42 = "B"
   {0x1C,0x3E,0x63,0x41,0x41,0x63,0x22,0x00}, //  67 = 0x43 = "C"
   {0x41,0x7F,0x7F,0x41,0x63,0x3E,0x1C,0x00}, //  68 = 0x44 = "D"
   {0x7F,0x7F,0x49,0x49,0x49,0x41,0x63,0x00}, //  69 = 0x45 = "E"
   {0x41,0x7F,0x7F,0x49,0x09,0x09,0x03,0x00}, //  70 = 0x46 = "F"
   {0x3E,0x7F,0x41,0x51,0x51,0x73,0x32,0x00}, //  71 = 0x47 = "G"
   {0x7F,0x7F,0x08,0x08,0x08,0x7F,0x7F,0x00}, //  72 = 0x48 = "H"
   {0x00,0x00,0x41,0x7F,0x7F,0x41,0x00,0x00}, //  73 = 0x49 = "I"
   {0x30,0x70,0x41,0x7F,0x3F,0x01,0x00,0x00}, //  74 = 0x4A = "J"
   {0x7F,0x7F,0x08,0x1C,0x36,0x63,0x41,0x00}, //  75 = 0x4B = "K"
   {0x41,0x7F,0x7F,0x41,0x40,0x40,0x60,0x00}, //  76 = 0x4C = "L"
   {0x7F,0x7F,0x06,0x1C,0x06,0x7F,0x7F,0x00}, //  77 = 0x4D = "M"
   {0x7F,0x7F,0x0E,0x18,0x30,0x7F,0x7F,0x00}, //  78 = 0x4E = "N"
   {0x3E,0x7F,0x41,0x41,0x41,0x7F,0x3E,0x00}, //  79 = 0x4F = "O"
   {0x41,0x7F,0x7F,0x49,0x09,0x0F,0x06,0x00}, //  80 = 0x50 = "P"
   {0x3E,0x7F,0x41,0x61,0x41,0xFF,0xBE,0x00}, //  81 = 0x51 = "Q"
   {0x7F,0x7F,0x09,0x19,0x39,0x6F,0x46,0x00}, //  82 = 0x52 = "R"
   {0x26,0x6F,0x49,0x49,0x49,0x7B,0x32,0x00}, //  83 = 0x53 = "S"
   {0x00,0x03,0x41,0x7F,0x7F,0x41,0x03,0x00}, //  84 = 0x54 = "T"
   {0x3F,0x7F,0x40,0x40,0x40,0x7F,0x3F,0x00}, //  85 = 0x55 = "U"
   {0x0F,0x1F,0x30,0x60,0x30,0x1F,0x0F,0x00}, //  86 = 0x56 = "V"
   {0x7F,0x7F,0x30,0x1C,0x30,0x7F,0x7F,0x00}, //  87 = 0x57 = "W"
   {0x41,0x63,0x3E,0x1C,0x3E,0x63,0x41,0x00}, //  88 = 0x58 = "X"
   {0x00,0x07,0x4F,0x78,0x78,0x4F,0x07,0x00}, //  89 = 0x59 = "Y"
   {0x43,0x61,0x71,0x59,0x4D,0x47,0x63,0x00}, //  90 = 0x5A = "Z"
   {0x00,0x7F,0x7F,0x41,0x41,0x41,0x00,0x00}, //  91 = 0x5B = "["
   {0x01,0x03,0x06,0x0C,0x18,0x30,0x60,0x00}, //  92 = 0x5C = "\"
   {0x00,0x41,0x41,0x41,0x7F,0x7F,0x00,0x00}, //  93 = 0x5D = "]"
   {0x08,0x0C,0x06,0x03,0x06,0x0C,0x08,0x00}, //  94 = 0x5E = "^"
   {0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80}, //  95 = 0x5F = "_"
   {0x00,0x00,0x03,0x07,0x04,0x00,0x00,0x00}, //  96 = 0x60 = "`"
   {0x20,0x74,0x54,0x54,0x7C,0x78,0x40,0x00}, //  97 = 0x61 = "a"
   {0x41,0x7F,0x7F,0x44,0x44,0x7C,0x38,0x00}, //  98 = 0x62 = "b"
   {0x38,0x7C,0x44,0x44,0x44,0x6C,0x28,0x00}, //  99 = 0x63 = "c"
   {0x38,0x7C,0x44,0x45,0x7F,0x7F,0x40,0x00}, // 100 = 0x64 = "d"
   {0x38,0x7C,0x54,0x54,0x54,0x5C,0x18,0x00}, // 101 = 0x65 = "e"
   {0x08,0x48,0x7E,0x7F,0x49,0x0B,0x02,0x00}, // 102 = 0x66 = "f"
   {0x18,0xBC,0xA4,0xA4,0xA8,0xFC,0x7C,0x00}, // 103 = 0x67 = "g"
   {0x41,0x7F,0x7F,0x04,0x04,0x7C,0x78,0x00}, // 104 = 0x68 = "h"
   {0x00,0x00,0x44,0x7D,0x7D,0x40,0x00,0x00}, // 105 = 0x69 = "i"
   {0x40,0xC0,0x80,0x84,0xFD,0x7D,0x00,0x00}, // 106 = 0x6A = "j"
   {0x41,0x7F,0x7F,0x10,0x38,0x6C,0x44,0x00}, // 107 = 0x6B = "k"
   {0x00,0x00,0x00,0x7F,0x7F,0x40,0x00,0x00}, // 108 = 0x6C = "l"
   {0x78,0x7C,0x0C,0x38,0x0C,0x7C,0x78,0x00}, // 109 = 0x6D = "m"
   {0x04,0x7C,0x78,0x04,0x04,0x7C,0x78,0x00}, // 110 = 0x6E = "n"
   {0x38,0x7C,0x44,0x44,0x44,0x7C,0x38,0x00}, // 111 = 0x6F = "o"
   {0x84,0xFC,0xF8,0xA4,0x24,0x3C,0x18,0x00}, // 112 = 0x70 = "p"
   {0x18,0x3C,0x24,0xA4,0xF8,0xFC,0x84,0x00}, // 113 = 0x71 = "q"
   {0x44,0x7C,0x78,0x44,0x04,0x0C,0x08,0x00}, // 114 = 0x72 = "r"
   {0x08,0x5C,0x54,0x54,0x54,0x74,0x20,0x00}, // 115 = 0x73 = "s"
   {0x04,0x04,0x3F,0x7F,0x44,0x64,0x20,0x00}, // 116 = 0x74 = "t"
   {0x3C,0x7C,0x40,0x40,0x3C,0x7C,0x40,0x00}, // 117 = 0x75 = "u"
   {0x0C,0x1C,0x30,0x60,0x30,0x1C,0x0C,0x00}, // 118 = 0x76 = "v"
   {0x3C,0x7C,0x60,0x30,0x60,0x7C,0x3C,0x00}, // 119 = 0x77 = "w"
   {0x44,0x6C,0x38,0x10,0x38,0x6C,0x44,0x00}, // 120 = 0x78 = "x"
   {0x1C,0xBC,0xA0,0xA0,0x90,0xFC,0x7C,0x00}, // 121 = 0x79 = "y"
   {0x4C,0x64,0x74,0x5C,0x4C,0x64,0x00,0x00}, // 122 = 0x7A = "z"
   {0x00,0x08,0x08,0x3E,0x77,0x41,0x41,0x00}, // 123 = 0x7B = "{"
   {0x00,0x00,0x00,0x77,0x77,0x00,0x00,0x00}, // 124 = 0x7C = "|"
   {0x00,0x41,0x41,0x77,0x3E,0x08,0x08,0x00}, // 125 = 0x7D = "}"
   {0x02,0x03,0x01,0x03,0x02,0x03,0x01,0x00}, // 126 = 0x7E = "~"
   {0x40,0x70,0x7C,0x4E,0x7C,0x70,0x40,0x00}};// 127 = 0x7F = ""
//============================================================================
 

franklee

New member
cfag12864 initialize code

We want to use a AT90S8535 microcontroller to drive a CFAg12864B-YYH-V Graphic LCD . we've been having a lot of problems trying to initialize the LCD, let alone trying to write something onto it. We are wondering if you guys have a sample C code initializing program for this specific LCD? (We've read the manual and there is some specifications that we don't know how to adjust (Duty ratio))
 

CF Tech

Administrator
Please take a look at the file attached above "AVR_KS0108_Demo_Code_Forum.zip". In it is low_lcd.c. Within that is the initialization code, written fro an AVR. I have pasted it in here for reference:
Code:
//============================================================================
// CFA-3335 Demonstration code
// LOW_LCD.C: Low-level lcd display routines.
// Samsung KS0107+KS0108 (S6B0107+S6B0108) LCD Controller
// Atmel ATMega32 processor @ 16MHz
// WinAVR / AVR GCC + Atmel AVR Studio
// Written by Brent A. Crosby
// Copyright 2005, Crystalfontz America, Inc. http://www.crystalfontz.com
//============================================================================
#include <avr/io.h>
#include <avr/iom32.h>
#include <string.h>
#include <avr/delay_x.h>
#include "typedefs.h"
#include "utils.h"
#include "low_lcd.h"
//============================================================================
//This is the display memory.
ubyte
  display[8][128];  //1024 bytes
//============================================================================
ubyte
  display_status;
//============================================================================
// 0 = backlight off.
// 1-19 = variable brightness
// 20 = backlight on
// You must call timer::Initialize_And_Start_Timer_2() before this will work.
//============================================================================
void write_both_lcd_control_registers(ubyte data)
  {
  //We need to wait until both controller's busy bits are clear.
  //Talk to the status (instruction) register.
  //(Must happen 140nS before the RISING edge of E.)
  PORTC&=~PORTC1_LCD_DI;
  //Tell the LCD we are going to be reading it
  //(Must happen 140nS before the RISING edge of E.)
  PORTC|=PORTC6_LCD_RW;
  //Talk to the left controller only
  //(Must happen 140nS before the RISING edge of E.)
  PORTC&=~PORTC0_LCD_CS1;
  PORTD|=PORTD6_LCD_CS2;
  //Make port A high-impedance
  DDRA=0x00;
  //Enable the selected controller's read data onto the port
  PORTC|=PORTC7_LCD_E;
  //The data is not valid for 320nS
  _delay_cycles(4); //375nS
  //Wait for the busy bit to drop
  while(PINA&0x80);
  //Terminate the read
  PORTC&=~PORTC7_LCD_E;

  //Talk to the right controller only
  PORTC|=PORTC0_LCD_CS1;   //125nS
  PORTD&=~PORTD6_LCD_CS2;  //125nS
  //(Must happen 140nS before the RISING edge of E.)
  //(E LOW pulse must be 450mS min)
  _delay_cycles(2);      //250nS

  //Enable the selected controller's read data onto the port
  PORTC|=PORTC7_LCD_E;
  //The data is not valid for 320nS
  _delay_cycles(4);
  //Wait for the busy bit to drop
  while(PINA&0x80);
  //Terminate the read
  PORTC&=~PORTC7_LCD_E;

  //Tell the LCD that we are writing to it.
  //(Must happen 140nS before the RISING edge of E.)
  PORTC&=~PORTC6_LCD_RW;    //125nS
   //Talk to both controllers
  //(Must happen 140nS before the RISING edge of E.)
  PORTC&=~PORTC0_LCD_CS1;   //125nS
  //stretch LOW E pulse width above the minimum of 450nS
  _delay_cycles(2);        //250nS
  //Strobe the E pin. We are still aimed at the status/instruction register.
  PORTC|=PORTC7_LCD_E;
  //Write the data to the output latches of port A
  //(Must happen 200nS before the FALLING edge of E.)
  PORTA=data;           //62.5nS
  //Go back to port A as an output
  DDRA=0xFF;            //125nS
  //stretch HIGH E pulse width above the minimum of 450nS
  _delay_cycles(3);    //312.5nS
  PORTC&=~PORTC7_LCD_E;
  }
//============================================================================
// PORTC0_LCD_CS1 and PORTD6_LCD_CS2 must be set to select the desired
// controller
//----------------------------------------------------------------------------
void write_lcd_data(ubyte data)
  {
  //We need to wait until the busy bit is clear.
  //Talk to the status (instruction) register.
  //(Must happen 140nS before the RISING edge of E.)
  PORTC&=~PORTC1_LCD_DI;
  //Tell the LCD we are going to be reading it
  //(Must happen 140nS before the RISING edge of E.)
  PORTC|=PORTC6_LCD_RW;
  //Make port A high-impedance
  DDRA=0x00;
  //Enable the selected controller's read data onto the port
  PORTC|=PORTC7_LCD_E;
  //The data from the LCD is not valid for 320nS
  _delay_cycles(4); //375nS
  //Wait for the busy bit to drop
  while(PINA&0x80);
  //Terminate the read
  PORTC&=~PORTC7_LCD_E;
  //Tell the LCD that we are writing to it.
  //(Must happen 140nS before the RISING edge of E.)
  PORTC&=~PORTC6_LCD_RW;   //125nS
  //Aim at the data register.
  //(Must happen 140nS before the RISING edge of E.)
  PORTC|=PORTC1_LCD_DI;   //125nS
  //stretch LOW E pulse width above the minimum of 450nS
  _delay_cycles(2);      //250nS
  //Strobe the E pin.
  PORTC|=PORTC7_LCD_E;
  //Write the data to the output latches of port A
  //(Must happen 200nS before the FALLING edge of E.)
  PORTA=data;            //62.5nS
  //Go back to port A as an output
  DDRA=0xFF;             //125nS
  //stretch HIGH E pulse width above the minimum of 450nS
  _delay_cycles(3);     //312.5nS
  //Terminate the write
  PORTC&=~PORTC7_LCD_E;
  }
//============================================================================
// Takes about 5.08ms (201.7KB/S) reading busy flag
void UpdateLCD(void)
  {
  register ubyte
    *left_data;
  register ubyte
    *right_data;
  register ubyte
    page_address;
  register ubyte
    column_address;

  //Initialize our source data pointers.
  left_data=&display[0][0];
  right_data=&display[0][64];

  //Make sure we are not in a write cycle
  PORTC&=~PORTC7_LCD_E;

  //Make sure the LCD thinks we are writing
  PORTC&=~PORTC6_LCD_RW;

  for(page_address=0;page_address<=7;page_address++)
    {
    //Set Y address (page, or horizontal stripe of 8 pixels) (controller docs call this "X")
    write_both_lcd_control_registers(0xB8|page_address);
    //Set X address 0 (right to left) (controller docs call this "Y")
    write_both_lcd_control_registers(0x40);

    for(column_address=0;column_address<=63;column_address++)
      {
      //Talk to the left controller only
      PORTC&=~PORTC0_LCD_CS1;
      PORTD|=PORTD6_LCD_CS2;
      write_lcd_data(*left_data++);
      //Talk to the right controller only
      PORTC|=PORTC0_LCD_CS1;
      PORTD&=~PORTD6_LCD_CS2;
      write_lcd_data(*right_data++);
      }
    //Skip down to the next line
    left_data+=64;
    right_data+=64;
    }
  }
//============================================================================
void InitializeLCD(void)
  {
  //Display on
  write_both_lcd_control_registers(0x3F);

  //Set Start Line 0
  write_both_lcd_control_registers(0xC0);

  //Clear the display memeory
  memset(display,0x00,sizeof(display));
  }
//============================================================================
 

franklee

New member
typedefs.h source files....????

i have try to find the typedefs.h and utils.h source files but i can't get them. can someone help me???? i really need your help. tq
 

CF Tech

Administrator
Sorry about that.
typedefs.h:
Code:
//============================================================================
typedef unsigned char ubyte;
typedef signed char sbyte;
typedef unsigned short uword;
typedef signed short sword;
typedef unsigned long dword;
typedef union
  {
  ubyte
    as_bytes[2];
  int
    as_int;
  }INT_UNION;
typedef union
  {
  ubyte
    as_bytes[2];
  uword
    as_word;
  }WORD_UNION;
typedef union
  {
  ubyte
    as_bytes[4];
  dword
    as_dword;
  }DWORD_UNION;
typedef union
  {
  ubyte
    as_bytes[4];
  uword
    as_words[2];
  dword
    as_dword;
  float
    as_float;
  }FLOAT_UNION;
//============================================================================
utils.h:
Code:
//============================================================================
void Set_Default_Port_Directions(void);
//============================================================================
//PORTA is the LCD data.
//============================================================================
#define PORTB0_KEY0                  0x01
#define PORTB1_KEY1                  0x02
#define PORTB2_KEY2                  0x04
#define PORTB3_CONTRAST_PWM          0x08
#define PORTB4_KEY3                  0x10
#define PORTB5_NC                    0x20
#define PORTB6_NC                    0x40
#define PORTB7_NC                    0x80
//============================================================================
#define PORTC0_LCD_CS1               0x01
#define PORTC1_LCD_DI                0x02
#define PORTC2_NC                    0x04
#define PORTC3_NC                    0x08
#define PORTC4_NC                    0x10
#define PORTC5_NC                    0x20
#define PORTC6_LCD_RW                0x40
#define PORTC7_LCD_E                 0x80
//============================================================================
#define PORTD0_RS_232_RX             0x01
#define PORTD1_RS_232_TX             0x02
#define PORTD2_NC                    0x04
#define PORTD3_DEBUG                 0x08
#define PORTD4_NC                    0x10
#define PORTD5_LCD_A_NC              0x20
#define PORTD6_LCD_CS2               0x40
#define PORTD7_BACKLIGHT_PWM         0x80
//============================================================================
utils.c
Code:
//============================================================================
// CFA-3335 Demonstration code
// UTILS.C: General utility routines
// Samsung KS0107+KS0108 (S6B0107+S6B0108) LCD Controller
// Atmel ATMega32 processor @ 16MHz
// WinAVR / AVR GCC + Atmel AVR Studio
// Written by Brent A. Crosby
// Copyright 2005, Crystalfontz America, Inc. http://www.crystalfontz.com
//============================================================================
#include <avr/io.h>
#include "typedefs.h"
#include "utils.h"
//============================================================================
//Time listed is the pulse width
//PORTD|=PORTD3_DEBUG;
//                     //125ns
//PORTD&=~PORTD3_DEBUG;
//
//PORTD|=PORTD3_DEBUG;
//__delay_cycles(1);  //187.5nS
//PORTD&=~PORTD3_DEBUG;
//
//PORTD|=PORTD3_DEBUG;
//__delay_cycles(2);  //250nS
//PORTD&=~PORTD3_DEBUG;
//
//PORTD|=PORTD3_DEBUG;
//__delay_cycles(3);  //312.5nS
//PORTD&=~PORTD3_DEBUG;
//
//PORTD|=PORTD3_DEBUG;
//__delay_cycles(4);  //375nS
//PORTD&=~PORTD3_DEBUG;
//
//PORTD|=PORTD3_DEBUG;
//__delay_cycles(5);  //437.5nS
//PORTD&=~PORTD3_DEBUG;
//
//PORTD|=PORTD3_DEBUG;
//__delay_cycles(6);  //500nS
//PORTD&=~PORTD3_DEBUG;
//============================================================================
// Port Direction Initialization.
//
// This routine will set the default processor port directions.
//----------------------------------------------------------------------------
void Set_Default_Port_Directions(void)
  {
  //Port A is the LCD data bus, default it to output.
  DDRA= 0xFF;
  PORTA=0x00;
  //   1111 1111 DDRA
  //   0000 0000 PORTA
  //   |||| ||||--PA0(ADC0) = LCD_DB0
  //   |||| |||---PA1(ADC1) = LCD_DB1
  //   |||| ||----PA2(ADC2) = LCD_DB2
  //   |||| |-----PA3(ADC3) = LCD_DB3
  //   ||||-------PA4(ADC4) = LCD_DB4
  //   |||--------PA5(ADC5) = LCD_DB5
  //   ||---------PA6(ADC6) = LCD_DB6
  //   |----------PA7(ADC7) = LCD_DB7

  //Set the default direction for port B. Keyn are setup as inputs with
  //pullups.
  DDRB= 0x08;
  PORTB=0x17;
  //   0000 1000 DDRB
  //   0001 0111 PORTB
  //   |||| ||||--PB0(XCK/T0)    = Key0
  //   |||| |||---PB1(T1)        = Key1
  //   |||| ||----PB2(AIN0/INT2) = Key2
  //   |||| |-----PB3(AIN1/OC0)  = Contrast_PWM
  //   ||||-------PB4(/SS)       = Key3
  //   |||--------PB5(MOSI)      = (Debug, unused, set to input)
  //   ||---------PB6(MISO)      = (Debug, unused, set to input)
  //   |----------PB7(SCK)       = (Debug, unused, set to input)

  //Set the default direction for port C.
  DDRC= 0xC3;
  PORTC=0x02;
  //   1100 0011 DDRC
  //   0000 0010 PORTC
  //   |||| ||||--PC0(SCL)   = LCD_CS1
  //   |||| |||---PC1(SDA)   = LCD_DI
  //   |||| ||----PC2(TCK)   = (Debug, unused, set to input)
  //   |||| |-----PC3(TMS)   = (Debug, unused, set to input)
  //   ||||-------PC4(TDO)   = (Debug, unused, set to input)
  //   |||--------PC5(TDI)   = (Debug, unused, set to input)
  //   ||---------PC6(TOSC1) = LCD_RW
  //   |----------PC7(TOSC2) = LCD_E

  //Set the default direction for port D.
  DDRD= 0xCA;
  PORTD=0x80;
  //   1100 1010 DDRD
  //   1000 0000 PORTD
  //   |||| ||||--PD0(RXD)  = RS_232_Rx
  //   |||| |||---PD1(TXD)  = RS_232_Tx
  //   |||| ||----PD2(INT0) = (unused, set to input)
  //   |||| |-----PD3(INT1) = (used for timing, set to output)
  //   ||||-------PD4(OC1B) = (unused, set to input)
  //   |||--------PD5(OC1A) = LCD /A(NC) (unused, set to input)
  //   ||---------PD6(ICP1) = LCD_CS2
  //   |----------PD7(OC2)  = Backlight PWM
  }
//============================================================================
 

franklee

New member
low_lcd.h source files

Thanks very much for the source files (utils.h and typedefs.h). i would like to try the Demonstration Code but i can't find source files for low_lcd.h. can someone please give me the source file of low_lcd.h.
 

franklee

New member
file in AVR_KS0108_Demo_Code_Forum.zip is can't opened

i had download AVR_KS0108_Demo_Code_Forum.zip. when i open it the file inside the zip folder can't opened. it look like corrupted. can u please attach it again. tq
 

Jambbe

New member
I have Avr Studio4 and WinAvr and if I try to build that typedefs.h file I only get redefiniton errors.
Has anybody any ideas what's the problem.

Code:
Build started 26.2.2007 at 21:39:23
avr-gcc.exe  -mmcu=atmega32 -Wall -gdwarf-2      -DF_CPU=14745600UL -Os -fsigned-char -MD -MP -MT infoview.o -MF dep/infoview.o.d  -c  ../infoview.c
In file included from ../utils.c:9,
                 from ../lcd_init.c:16,
                 from ../infoview.c:11:
../typedefs.h:3: error: redefinition of typedef 'ubyte'
../typedefs.h:3: error: previous declaration of 'ubyte' was here
../typedefs.h:4: error: redefinition of typedef 'sbyte'
../typedefs.h:4: error: previous declaration of 'sbyte' was here
../typedefs.h:5: error: redefinition of typedef 'uword'
../typedefs.h:5: error: previous declaration of 'uword' was here
../typedefs.h:6: error: redefinition of typedef 'sword'
../typedefs.h:6: error: previous declaration of 'sword' was here
../typedefs.h:7: error: redefinition of typedef 'dword'
../typedefs.h:7: error: previous declaration of 'dword' was here
../typedefs.h:14: error: conflicting types for 'INT_UNION'
../typedefs.h:14: error: previous declaration of 'INT_UNION' was here
../typedefs.h:21: error: conflicting types for 'WORD_UNION'
../typedefs.h:21: error: previous declaration of 'WORD_UNION' was here
../typedefs.h:28: error: conflicting types for 'DWORD_UNION'
../typedefs.h:28: error: previous declaration of 'DWORD_UNION' was here
../typedefs.h:39: error: conflicting types for 'FLOAT_UNION'
../typedefs.h:39: error: previous declaration of 'FLOAT_UNION' was here
In file included from ../infoview.c:11:
../lcd_init.c: In function `write_both_lcd_control_registers':
../lcd_init.c:50: warning: implicit declaration of function `_delay_cycles'
../lcd_init.c: In function `InitializeLCD':
../lcd_init.c:254: warning: implicit declaration of function `memset'
make: *** [infoview.o] Error 1
Build failed with 18 errors and 2 warnings...
 

CF Tech

Administrator
If you take all and only the files in the zip "AVR_KS0108_Demo_Code_Forum.zip" attached to the second post of this thread, it should build fine. Can you try making a clean directory, and building only the files from the zip?
 

Jambbe

New member
I got it work if I compiler that demo-code but in my own code it doesn't still work.
 
Last edited:
Top