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

TG19264A using C language

hgseric

New member
I have been working on interfacing a TG19264A to Silabs C8051F000 microcontroller but have been having some problems. Has anyone got a sample code for the KS0108 / KS0107 using C language that they would be willing to share?

Thanks in advance,

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

hgseric

New member
fs

I've seen through the program code.. but the language they using is C++ mine is C.. the program software i'm using is very troublesome.. i have to have to add this and that then can synchonize with the software.. how? I'm totally lost..
 

CF Tech

Administrator
Well, the demo code is only C++ in name, and how it relates to the windowing. The core stuff is C.

Basically there are some port defines in the top of the file and an initialization routine. Just find these and work on moving them to your platform.
 

hgseric

New member
fs

ok.. can i change the extension file to .c ? then i juz need to change some settings inside only? which is the file that i need to compile ? is it this==> BMP2ASM
 

CF Tech

Administrator
This is the only code you need to mess with, from CFAG_WinTestDlg.cpp

You need to port these macros to your system:
Code:
#define DATA_ADDR (port_data_address)
#define CONT_ADDR (port_control_address)
  
//inverted at the port
#define CLR_CS1 (DlPortWritePortUchar(CONT_ADDR,(control|=0x02)));(Sleep(1))
#define FCLR_E (DlPortWritePortUchar(CONT_ADDR,(control|=0x02)))
#define SET_CS1 (DlPortWritePortUchar(CONT_ADDR,(control&=~0x02)))
  
//straight at the port
#define SET_RS (DlPortWritePortUchar(CONT_ADDR,(control|=0x04)))
#define CLR_RS (DlPortWritePortUchar(CONT_ADDR,(control&=~0x04)))

//inverted at the port
#define CLR_CS2 (DlPortWritePortUchar(CONT_ADDR,(control|=0x08)))
#define SET_CS2 (DlPortWritePortUchar(CONT_ADDR,(control&=~0x08)))

//inverted at the port
#define CLR_E (DlPortWritePortUchar(CONT_ADDR,(control|=0x01)))
#define SET_E (DlPortWritePortUchar(CONT_ADDR,(control&=~0x01)))


#define DATA(x) (DlPortWritePortUchar(DATA_ADDR,(x)));(Sleep(1))
#define FDATA(x) (DlPortWritePortUchar(DATA_ADDR,(x)))
And then this initialization routine is fairly straight forward:
Code:
void initialize_and_put_checkerboard() 
  {
  ubyte
    i;
  i=0;
  ubyte
    data;
  data=0xAA;

  //Reset should be an R-C in the hardware.
  //R/W is set permanently low in the hardware (write-only)

  //These things prety much initialize themselves

  //Idle E
  CLR_E;

  //Talk to the control register.
  CLR_RS;

  //Talk to both controllers
  CLR_CS1;
  CLR_CS2;

  //Display on
  DATA(0x3F);
  SET_E;
  CLR_E;
  Sleep(10);

  //Set Start Line 0
  DATA(0xC0);
  SET_E;
  CLR_E;
  Sleep(10);

  int
    row;
  for(row=0;row<=7;row++)
    {
    //Set X address
    DATA(0xB8|row);
    SET_E;
    CLR_E;
    Sleep(1);

    //Set Y address 0
    DATA(0x40);
    SET_E;
    CLR_E;
    Sleep(1);

    //Aim at the data register.
    SET_RS;

    //Talk to controller 1 only
    SET_CS1;

    int
      col;
    for(col=0;col<=63;col++)
      {
      FDATA(data);
      SET_E;
      Sleep(1);
      CLR_E;
      Sleep(1);
      data^=0xFF;
      }

    //Talk to the controller 2
    CLR_CS1;
    SET_CS2;

    for(col=64;col<=127;col++)
      {
      FDATA(data);
      SET_E;
      Sleep(1);
      CLR_E;
      Sleep(1);
      data^=0xFF;
      }
    
    //Talk to both controllers
    CLR_CS1;
    CLR_CS2;

    //Aim back to the control register.
    CLR_RS;
    }
  }
 

hgseric

New member
defining

can i define it in this way?
Code:
#include <c8051f000.h>							
#include <stdio.h>
                     
sbit 	E   = P0^1;
sbit 	CS1 = P0^0;
sbit 	CS2 = P0^4;

#define DB7 = P1^7
#define DB6 = P1^6
#define DB5 = P1^5
#define DB4 = P1^4
#define DB3 = P1^3
#define DB2 = P1^2
#define DB1 = P1^1
#define DB0 = P1^0

#define DI = P0^5
#define RW = P0^3

void main()

{
 	
}
 
Last edited:

hgseric

New member
Port input/output

How do i set the XBR0, XBR1 accordingly? Which specs I must look at to set these XBR0 and XBR1?
 

hgseric

New member
What about this?

Oh.. ok thanks.. Then may I know what are these for? (SDA, SCL, SCK, MISO, MOSI, NSS, TX, RX, CEX0-4, ECI, CP0, CP1, T0, /INT0, T1, /INT1, T2, T2EX, /SYSCLK, CNVSTR) Can I know each of this definition and when I need them for operation?
 

CF Tech

Administrator
Is that list from the Silabs or the display? Well, in either case, you will have to go to the data sheet for the appropriate part and read up on the signals.
 

CF Tech

Administrator
Sure, some I recognize. Shall we test me?

SDA: I2C clock
SCL: I2C data
SCK: SPI clock
MISO: SPI Master In Slave Out
MOSI: SPI Master Out Slave In
NSS: (probably) SPI Slave Select Not
TX: UART Transmit
RX: UART Receive
CEX0-4: ?
ECI: ?
CP0,CP1: Maybe external selects
T0: Maybe a timer output
/INT0: External Interrupt
T1: Maybe a timer output
/INT1: External Interrupt
T2: Maybe a timer output
T2EX: ?
/SYSCLK: Maybe the system clock
CNVSTR: ?

But where does that get you? You are no closer than before.

First you need to become familiar enough with you microcontroller so that you can communicate and move the pins up and down. Once you get familiar with the microcontroller, then these questions and answers will make more sense.
 

hgseric

New member
oh ok.. i get what u say but i wanted to know what are this pin for so i can get the effect i wanted.. i show u the latest code i've type give mi some comments..
Code:
#include <c8051f000.h>							
#include <c8051f000.h>							
#include <stdio.h>


                     
sbit E   = P0^1;
sbit CS1 = P0^0;
sbit CS2 = P0^4;

sbit DB7 = P1^7;
sbit DB6 = P1^6;
sbit DB5 = P1^5;
sbit DB4 = P1^4;
sbit DB3 = P1^3;
sbit DB2 = P1^2;
sbit DB1 = P1^1;
sbit DB0 = P1^0;

sbit DI = P0^5;
sbit RW = P0^3;

#define LCD_ON() {(0x3F);}
#define LCD_OFF() {(0x3E);}



void config (void) {

//Local Variable Definitions

	

//----------------------------------------------------------------
// Watchdog Timer Configuration (use as default)
//
// WDTCN.[7:0]: WDT Control
//   Writing 0xA5 enables and reloads the WDT.
//   Writing 0xDE followed within 4 clocks by 0xAD disables the WDT
//   Writing 0xFF locks out disable feature.
//
// WDTCN.[2:0]: WDT timer interval bits
//   NOTE! When writing interval bits, bit 7 must be a 0.
//
//  Bit 2 | Bit 1 | Bit 0
//------------------------     
//    1   |   1   |   1      Timeout interval = 1048576 x Tsysclk
//    1   |   1   |   0      Timeout interval =  262144 x Tsysclk
//    1   |   0   |   1      Timeout interval =   65636 x Tsysclk
//    1   |   0   |   0      Timeout interval =   16384 x Tsysclk
//    0   |   1   |   1      Timeout interval =    4096 x Tsysclk
//    0   |   1   |   0      Timeout interval =    1024 x Tsysclk
//    0   |   0   |   1      Timeout interval =     256 x Tsysclk
//    0   |   0   |   0      Timeout interval =      64 x Tsysclk
// 
//------------------------

	WDTCN = 0x07;	// Watchdog Timer Control Register

//----------------------------------------------------------------
// CROSSBAR REGISTER CONFIGURATION 
//
// NOTE: The crossbar register should be configured before any  
// of the digital peripherals are enabled. The pinout of the 
// device is dependent on the crossbar configuration so caution 
// must be exercised when modifying the contents of the XBR0, 
// XBR1, and XBR2 registers. For detailed information on 
// Crossbar Decoder Configuration, refer to Application Note 
// AN001, "Configuring the Port I/O Crossbar Decoder". 
//----------------------------------------------------------------

// Configure the XBRn Registers

	XBR0 = 0x00;	// XBAR0: Initial Reset Value
	XBR1 = 0x00;	// XBAR1: Initial Reset Value
	XBR2 = 0x40;	// XBAR2: enable crossbar
// Select Pin I/0

// NOTE: Some peripheral I/O pins can function as either inputs or 
// outputs, depending on the configuration of the peripheral. By default,
// the configuration utility will configure these I/O pins as push-pull 
// outputs.
                      // Port configuration (1 = Push Pull Output)
	PRT0CF = 0x00; // Output configuration for P0 
	PRT1CF = 0x00; // Output configuration for P1 
	PRT2CF = 0x00; // Output configuration for P2 
	PRT3CF = 0x00; // Output configuration for P3 

// View port pinout

		// The current Crossbar configuration results in the 
		// following port pinout assignment:
		// Port 0
		// P0.0 = unassigned      (Open-Drain Output/Input)
		// P0.1 = unassigned      (Open-Drain Output/Input)
		// P0.2 = unassigned      (Open-Drain Output/Input)
		// P0.3 = unassigned      (Open-Drain Output/Input)
		// P0.4 = unassigned      (Open-Drain Output/Input)
		// P0.5 = unassigned      (Open-Drain Output/Input)
		// P0.6 = unassigned      (Open-Drain Output/Input)
		// P0.7 = unassigned      (Open-Drain Output/Input)

		// Port 1
		// P1.0 = unassigned      (Open-Drain Output/Input)
		// P1.1 = unassigned      (Open-Drain Output/Input)
		// P1.2 = unassigned      (Open-Drain Output/Input)
		// P1.3 = unassigned      (Open-Drain Output/Input)
		// P1.4 = unassigned      (Open-Drain Output/Input)
		// P1.5 = unassigned      (Open-Drain Output/Input)
		// P1.6 = unassigned      (Open-Drain Output/Input)
		// P1.7 = unassigned      (Open-Drain Output/Input)
					
		// Port 2		
		// P2.0 = unassigned      (Open-Drain Output/Input)
		// P2.1 = unassigned      (Open-Drain Output/Input)
		// P2.2 = unassigned      (Open-Drain Output/Input)
		// P2.3 = unassigned      (Open-Drain Output/Input)
		// P2.4 = unassigned      (Open-Drain Output/Input)
		// P2.5 = unassigned      (Open-Drain Output/Input)
		// P2.6 = unassigned      (Open-Drain Output/Input)
		// P2.7 = unassigned      (Open-Drain Output/Input)

		// Port 3		
		// P3.0 = unassigned      (Open-Drain Output/Input)
		// P3.1 = unassigned      (Open-Drain Output/Input)
		// P3.2 = unassigned      (Open-Drain Output/Input)
		// P3.3 = unassigned      (Open-Drain Output/Input)
		// P3.4 = unassigned      (Open-Drain Output/Input)
		// P3.5 = unassigned      (Open-Drain Output/Input)
		// P3.6 = unassigned      (Open-Drain Output/Input)
		// P3.7 = unassigned      (Open-Drain Output/Input)

//----------------------------------------------------------------
// Comparators Register Configuration (use as default)
//
// Bit 7  | Bit 6  | Bit 5  | Bit 4  | Bit 3 | Bit 2 | Bit 1 | Bit 0
//------------------------------------------------------------------     
//  R/W	  |    R   |  R/W   |  R/W   |  R/W  |  R/W  |  R/W  |  R/W
//------------------------------------------------------------------
// Enable | Output | Rising | Falling|  Positive     |  Negative    
//        | State  | Edge   | Edge   |  Hysterisis   |  Hysterisis    
//        | Flag   | Int.   | Int.   |  00: Disable  |  00: Disable
//        |        | Flag   | Flag   |  01:  5mV     |  01:  5mV  
//        |        |        |        |  10: 10mV     |  10: 10mV
//        |        |        |        |  11: 20mV     |  11: 20mV 
// ----------------------------------------------------------------

	CPT0CN = 0x00;	// Comparator 0 Control Register
	

	CPT1CN = 0x00;	// Comparator 1 Control Register
	
	//Comp1 marker
					
//----------------------------------------------------------------
// Oscillator Configuration
//----------------------------------------------------------------

	OSCXCN = 0x30;	// EXTERNAL Oscillator Control Register	(use as default)

	OSCICN = 0x96;	// Internal Oscillator Control Register (10010110b)

	
//----------------------------------------------------------------
// Reference Control Register Configuration (use as default)
//----------------------------------------------------------------

	REF0CN = 0x00;	// Reference Control Register

//----------------------------------------------------------------
// SPI Configuration (use as default)
//----------------------------------------------------------------

	SPI0CN = 0x00;	// SPI Control Register
	SPI0CFG = 0x00;	// SPI Configuration Register
	SPI0CKR = 0x00;	// SPI Clock Rate Register

//----------------------------------------------------------------
// DAC Configuration (use as default)
//----------------------------------------------------------------

	DAC0CN = 0x00;	// DAC0 Control Register
	DAC0L = 0x00;	// DAC0 Low Byte Register
	DAC0H = 0x00;	// DAC0 High Byte Register

	DAC1CN = 0x00;	// DAC1 Control Register
	DAC1L = 0x00;	// DAC1 Low Byte Register
	DAC1H = 0x00;	// DAC1 High Byte Register
//----------------------------------------------------------------
// UART Configuration (use as default)
//----------------------------------------------------------------

	SCON = 0x00;		// Serial Port Control Register
	PCON = 0x00;		// Power Control Register
	

//----------------------------------------------------------------
// SMBus Configuration (use as default)
//----------------------------------------------------------------

	SMB0CN = 0x00;	// SMBus Control Register
	SMB0ADR = 0x00;	// SMBus Address Register
	SMB0CR = 0x00;	// SMBus Clock Rate Register


//----------------------------------------------------------------
// PCA Configuration (use as default)
//----------------------------------------------------------------

	PCA0MD = 0x00;	    // PCA Mode Register
	PCA0CN = 0x00;	    // PCA Control Register
    PCA0H = 0x00;       // PCA Counter/Timer High Byte	
    PCA0L = 0x00;       // PCA Counter/Timer Low Byte
	

	//Module 0
	PCA0CPM0 = 0x00;	// PCA Capture/Compare Register 0
	PCA0CPL0 = 0x00;	// PCA Counter/Timer Low Byte
	PCA0CPH0 = 0x00;	// PCA Counter/Timer High Byte

	//Module 1
	PCA0CPM1 = 0x00;	// PCA Capture/Compare Register 1
	PCA0CPL1 = 0x00;	// PCA Counter/Timer Low Byte
	PCA0CPH1 = 0x00;	// PCA Counter/Timer High Byte

	//Module 2
	PCA0CPM2 = 0x00;	// PCA Capture/Compare Register 2
	PCA0CPL2 = 0x00;	// PCA Counter/Timer Low Byte
	PCA0CPH2 = 0x00;	// PCA Counter/Timer High Byte

	//Module 3
	PCA0CPM3 = 0x00;	// PCA Capture/Compare Register 3
	PCA0CPL3 = 0x00;	// PCA Counter/Timer Low Byte
	PCA0CPH3 = 0x00;	// PCA Counter/Timer High Byte

	//Module 4
	PCA0CPM4 = 0x00;	// PCA Capture/Compare Register 4
	PCA0CPL4 = 0x00;	// PCA Counter/Timer Low Byte
	PCA0CPH4 = 0x00;	// PCA Counter/Timer High Byte

//----------------------------------------------------------------
// ADC Configuration (use as default)
//----------------------------------------------------------------

	AMX0CF = 0x60;	// AMUX Configuration Register
	AMX0SL = 0x00;	// AMUX Channel Select Register
	ADC0CF = 0x00;	// ADC Configuration Register
	ADC0CN = 0x00;	// ADC Control Register
	
	ADC0LTH = 0x00;	// ADC Less-Than High Byte Register
	ADC0LTL = 0x00;	// ADC Less-Than Low Byte Register
	ADC0GTH = 0xFF;	// ADC Greater-Than High Byte Register
	ADC0GTL = 0xFF;	// ADC Greater-Than Low Byte Register


	
//----------------------------------------------------------------
// Timer Configuration (use as default)
//----------------------------------------------------------------

	CKCON = 0x00;	// Clock Control Register
	TH0 = 0x00;		// Timer 0 High Byte
	TL0 = 0x00;		// Timer 0 Low Byte
	TH1 = 0x00;		// Timer 1 High Byte
	TL1 = 0x00;		// Timer 1 Low Byte
	TMOD = 0x00;	// Timer Mode Register
	TCON = 0x00;	// Timer Control Register 

	RCAP2H = 0x00;	// Timer 2 Capture Register High Byte
	RCAP2L = 0x00;	// Timer 2 Capture Register Low Byte	
	TH2 = 0x00;		// Timer 2 High Byte	
	TL2 = 0x00;		// Timer 2 Low Byte	
    T2CON = 0x00;	// Timer 2 Control Register	
		
	TMR3RLL = 0x00;	// Timer 3 Reload Register Low Byte
	TMR3RLH = 0x00;	// Timer 3 Reload Register High Byte
	TMR3H = 0x00;	// Timer 3 High Byte
	TMR3L = 0x00;	// Timer 3 Low Byte
    TMR3CN = 0x00;	// Timer 3 Control Register
	
	


//----------------------------------------------------------------
// Reset Source Configuration (use as default)
//
// Bit 7  | Bit 6  | Bit 5  | Bit 4  | Bit 3 | Bit 2 | Bit 1 | Bit 0
//------------------------------------------------------------------     
//    R	 |   R/W  |  R/W   |  R/W   |   R   |   R   |  R/W  |  R
//------------------------------------------------------------------
//  JTAG  |Convert | Comp.0 | S/W    | WDT   | Miss. | POR   | HW
// Reset  |Start   | Reset/ | Reset  | Reset | Clock | Force | Pin
// Flag   |Reset/  | Enable | Force  | Flag  | Detect| &     | Reset
//        |Enable  | Flag   | &      |       | Flag  | Flag  | Flag
//        |Flag    |        | Flag   |       |       |       |
//------------------------------------------------------------------
// NOTE! : Comparator 0 must be enabled before it is enabled as a 
// reset source.
//
// NOTE! : External CNVSTR must be enalbed through the crossbar, and
// the crossbar enabled prior to enabling CNVSTR as a reset source 
//------------------------------------------------------------------

	RSTSRC = 0x00;	// Reset Source Register


//----------------------------------------------------------------
// Interrupt Configuration (use as default)
//----------------------------------------------------------------

	IE = 0x00;		    //Interrupt Enable
	IP = 0x00;		    //Interrupt Priority
	EIE1 = 0x00;		//Extended Interrupt Enable 1
	EIE2 = 0x00;		//Extended Interrupt Enable 2
	EIP1 = 0x00;		//Extended Interrupt Priority 1
	EIP2 = 0x00;		//Extended Interrupt Priority 2

	

// other initialization code here...



}   //End of config


void data_write(unsigned char x)
{
DI = 1;
RW = 0;
P1 = x;

}

void data_read(unsigned char x)
{
DI = 1;
RW = 1;
P1 = x;

}

void DIS_START_LINE(unsigned char x)
{
DI = 0;
RW = 0;
P1 = x;

}

void SET_PG(unsigned char x)
{
DI = 0;
RW = 0;
P1 = x;

}

void SET_ADD(unsigned char x)
{
DI = 0;
RW = 0;
P1 = x;

}

void STATUS_RD(unsigned char x)
{
DI = 0;
RW = 1;
P1 = x;

}
int main(void)
{
 	
	config();
	LCD_ON();
	data_read(0xC0);
   	data_write(0x48);
    DIS_START_LINE(0xFF);
	SET_PG(0xBF);
	SET_ADD(0x7F);
	STATUS_RD(0x00);
}
 
Last edited:

CF Tech

Administrator
This would be my best shot, not knowing the processor, and not being able to compile:
Code:
#include <c8051f000.h>							
#include <stdio.h>

sbit E   = P0^1;
sbit CS1 = P0^0;
sbit CS2 = P0^4;

sbit DB7 = P1^7;
sbit DB6 = P1^6;
sbit DB5 = P1^5;
sbit DB4 = P1^4;
sbit DB3 = P1^3;
sbit DB2 = P1^2;
sbit DB1 = P1^1;
sbit DB0 = P1^0;

sbit DI = P0^5;
sbit RW = P0^3;

//====================================================================
void config (void)
  {
  //Local Variable Definitions
  . . . . omitted for clarity
  }   //End of config
//====================================================================
//Just guessing here, too long won't hurt. Time it with your scope & tweak it if you can.
void Sleep(int milliseconds)
  {
  int
    i,j,k,l;
  for(i=0;i<=milliseconds;i++)
    for(j=0;j<=10000;j++)
      for(k=0;k<=10000;k++)
        for(l=0;l<=10000;l++);
  }
//====================================================================
//Your ported macros to control the pins should look something like this
#define CLR_CS1 (CS1=0)
#define SET_CS1 (CS1=1)
#define SET_RS  (RS=1)
#define CLR_RS  (RS=0)
#define CLR_CS2 (CS2=0)
#define SET_CS2 (CS2=1)
#define CLR_E   (E=0)
#define SET_E   (E=1)

#define DATA(x) (P1=(x))
//====================================================================
void initialize_and_put_checkerboard(void) 
  {
  ubyte
    i;
  i=0;
  ubyte
    data;
  data=0xAA;

  //Reset should be an R-C in the hardware.
  //Write, this demo does not read
  RW=0;

  //These things pretty much initialize themselves

  //Idle E
  CLR_E;

  //Talk to the control register.
  CLR_RS;

  //Talk to both controllers
  CLR_CS1;
  CLR_CS2;

//There are a bucket load of "Sleep()" calls in here. Once you get it running
//you can work on speeding it up.

  //Display on
  DATA(0x3F);
  Sleep(1);
  SET_E;
  Sleep(1);
  CLR_E;
  Sleep(10);

  //Set Start Line 0
  DATA(0xC0);
  Sleep(1);
  SET_E;
  Sleep(1);
  CLR_E;
  Sleep(10);

  int
    row;
  for(row=0;row<=7;row++)
    {
    //Set X address
    DATA(0xB8|row);
    Sleep(1);
    SET_E;
    Sleep(1);
    CLR_E;
    Sleep(1);

    //Set Y address 0
    DATA(0x40);
    Sleep(1);
    SET_E;
    Sleep(1);
    CLR_E;
    Sleep(1);

    //Aim at the data register.
    SET_RS;

    //Talk to controller 1 only
    SET_CS1;

    int
      col;
    for(col=0;col<=63;col++)
      {
      DATA(data);
      Sleep(1);
      SET_E;
      Sleep(1);
      CLR_E;
      Sleep(1);
      data^=0xFF;
      }

    //Talk to the controller 2
    CLR_CS1;
    SET_CS2;

    for(col=64;col<=127;col++)
      {
      DATA(data);
      Sleep(1);
      SET_E;
      Sleep(1);
      CLR_E;
      Sleep(1);
      data^=0xFF;
      }
    
    //Talk to both controllers
    CLR_CS1;
    CLR_CS2;

    //Aim back to the control register.
    CLR_RS;
    }
  }
//====================================================================
int main(void)
  {
  config();
  initialize_and_put_checkerboard();
  //wait forever
  while(1);
  }
//====================================================================
 
Top