Forum: Mikrocontroller und Digitale Elektronik MI0283qt2 - Inbetriebsetzung


von Franz (geatschi2)


Lesenswert?

Hallo..

Ich habe folgendes Problem:

Ich will das MI0283qt mit dem XC164 ansteuern.

Die Kommunikation sollte funktionieren, da ich eine vorgefertigte datei 
verwendet habe..Leider zeigt das Display nichts an. Nur die 
Hintergrundbeleutung leuchtet. Ich weis auch nicht genau, was ich ans 
Diplay schicken muss, dass z.B. ein Strich oder ein Viereck zusehen ist.

Hier mein Programm Code:

main.c
------------------------------------------------------------------------ 
-----
#include <XC164.h>
#include <intrins.h>
#include "main.h"
#include "spi.h"
#include "display.h"
#include "touch.h"


void delay(unsigned long i)
{
  while(i--)
  {
     _nop_();
  }
}


void main()
{
  DP1L |= 0x03;    // init Reset and /CS_LCD
  P1L  |= 0x03;    // disable Reset and /CS_LCD

    init_spi();
  init_touch();
  lcd_reset();


  while(!PEN_DETECT());





  //lcd_clear(RGB(0x00,0x00,0x00));
  lcd_clear(RGB(0xFF,0x00,0x00));
  //lcd_clear(RGB(0x00,0xFF,0x00));
  //lcd_clear(RGB(0x00,0x00,0xFF));

    while (1)
    {
    _nop_();
    }
}----------------------------------------------------------------------- 
-

dsiplay.c

#include <XC164.h>
#include <intrins.h>
#include "main.h"
#include "spi.h"
#include "display.h"



void lcd_drawstop(void)
{
  LCD_CS_DISABLE();

  return;
}


void lcd_drawstart(void)
{
  LCD_CS_ENABLE();
  write_spi(LCD_REGISTER);
  write_spi(0x22);
  LCD_CS_DISABLE();

  LCD_CS_ENABLE();
  write_spi(LCD_DATA);

  return;
}


void lcd_area(unsigned int x0, unsigned int y0, unsigned int x1, 
unsigned int y1)
{
  lcd_cmd(0x03, (x0>>0)); //set x0
  lcd_cmd(0x02, (x0>>8)); //set x0
  lcd_cmd(0x05, (x1>>0)); //set x1
  lcd_cmd(0x04, (x1>>8)); //set x1
  lcd_cmd(0x07, (y0>>0)); //set y0
  lcd_cmd(0x06, (y0>>8)); //set y0
  lcd_cmd(0x09, (y1>>0)); //set y1
  lcd_cmd(0x08, (y1>>8)); //set y1

  return;
}


void lcd_cursor(unsigned int x, unsigned int y)
{
  lcd_area(x, y, x, y);

  return;
}


void lcd_cmd(unsigned int reg, unsigned int param)
{
  LCD_CS_ENABLE();
  write_spi(LCD_REGISTER);
  write_spi(reg);
  LCD_CS_DISABLE();

  LCD_CS_ENABLE();
  write_spi(LCD_DATA);
  write_spi(param);
  LCD_CS_DISABLE();

  return;
}


void lcd_data(unsigned int c)
{
  LCD_CS_ENABLE();
  write_spi(LCD_DATA);
  write_spi(c>>8);
  write_spi(c);
  LCD_CS_DISABLE();

  return;
}


void lcd_reset(void)
{
  //reset
  LCD_CS_DISABLE();
  LCD_RST_ENABLE();
  delay(10000);
  LCD_RST_DISABLE();
  delay(10000);

  //driving ability
  lcd_cmd(0xEA, 0x0000);
  lcd_cmd(0xEB, 0x0020);
  lcd_cmd(0xEC, 0x000C);
  lcd_cmd(0xED, 0x00C4);
  lcd_cmd(0xE8, 0x0040);
  lcd_cmd(0xE9, 0x0038);
  lcd_cmd(0xF1, 0x0001);
  lcd_cmd(0xF2, 0x0010);
  lcd_cmd(0x27, 0x00A3);

  //power voltage
  lcd_cmd(0x1B, 0x001B);
  lcd_cmd(0x1A, 0x0001);
  lcd_cmd(0x24, 0x002F);
  lcd_cmd(0x25, 0x0057);

  //VCOM offset
  lcd_cmd(0x23, 0x008D); //for flicker adjust

  //power on
  lcd_cmd(0x18, 0x0036);
  lcd_cmd(0x19, 0x0001); //start osc
  lcd_cmd(0x01, 0x0000); //wakeup
  lcd_cmd(0x1F, 0x0088);
  delay(10000);
  lcd_cmd(0x1F, 0x0080);
  delay(10000);
  lcd_cmd(0x1F, 0x0090);
  delay(10000);
  lcd_cmd(0x1F, 0x00D0);
  delay(10000);

  //color selection
  lcd_cmd(0x17, 0x0005); //0x0005=65k, 0x0006=262k

  //panel characteristic
  lcd_cmd(0x36, 0x0000);
  delay(10000);

  //lcd_cmd(0x3c, 0x00FF);
  //lcd_cmd(0x3d, 0x0004);
  //lcd_cmd(0x3f, 0x00FF);

  //display on
  lcd_cmd(0x28, 0x0038);
  delay(10000);
  lcd_cmd(0x28, 0x003C);

  //display options
#ifdef LCD_MIRROR
  lcd_cmd(0x16, 0x0068); //MY=0 MX=1 MV=1 ML=0 BGR=1
#else
  lcd_cmd(0x16, 0x00A8); //MY=1 MX=0 MV=1 ML=0 BGR=1
#endif

  lcd_area(0, 0, (LCD_WIDTH-1), (LCD_HEIGHT-1));

  return;
}


void lcd_clear(unsigned int color)
{
  unsigned int i;

  lcd_cursor(40,40);
  //lcd_area(0, 0, (LCD_WIDTH-1), (LCD_HEIGHT-1));
  lcd_drawstart();
   //for(i=0;i<(LCD_WIDTH*LCD_HEIGHT);i++)
  //{
    lcd_data(color);
  //}
  lcd_drawstop();

}

------------------------------------------------------------------------ 
--

spi.c

#include <XC164.h>
#include <intrins.h>
#include "spi.h"
#include "display.h"

void init_spi(void) {

  // Enable access to control bits
  SSC0_CON_EN = 0;

  SSC0_CON = 0xC037;
  SSC0_BR = 0;           // full speed

  /* _bfld_() sets bits via bit mask of the specified SFR
   *  void bfld ( unsigned int sfr,      // the SFR name
   *                int mask,              // the data bits mask
   *                int data);             // the data value
   */
  _bfld_(ALTSEL0P3,0x2300,0x2200); /* Select alternate functions SCLK 
and MTSR */
  _bfld_(P3,0x2300,0x2200);        /* Must set Port 3 latch due to "AND" 
configuration */
  _bfld_(DP3,0x2300,0x2200);       /* Set input/output directions */

  SSC0_CON_EN = 1;
}

unsigned char write_spi(unsigned char byte)
{
   SSC0_TB = byte;                       // write byte to transmit 
buffer
   while(SSC0_CON_BSY);
   return (SSC0_RB & 0xFF);                            //return received 
value
}
------------------------------------------------------------------------ 
--
 touch.c
#include <XC164.h>
#include <intrins.h>
#include "spi.h"
#include "display.h"
#include "touch.h"


void init_touch(void) {

  DP1L |= 0x80;    // init /CS_TOUCH
  P1L  |= 0x80;    // disable /CS_TOUCH

  DP9  &= 0xFC;   // BUSY and IRQ as input
}
------------------------------------------------------------------------ 
--

/*---------------------------------------------------------------------- 
----
INTRINS.H

Intrinsic functions
for C166/EC++ Version 5.
Copyright (c) 1992-2004 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
------------------------------------------------------------------------ 
--*/

#ifndef _INTRINS_H_
#define _INTRINS_H_

#ifdef __cplusplus               // EC++
extern "C"  {
#endif

void       nop (void);
void      idle (void);
void    srvwdt (void);
void     pwrdn (void);
void    diswdt (void);
void     einit (void);
void      bfld (unsigned int sfr_, unsigned mask1, unsigned mask2);
void      trap (int intno);
void    atomic (int n_instr);
void endatomic (void);
#if (_MODEL_ != 0)          /* if not tiny model */
unsigned int sof (void huge *adr);
#else
unsigned int sof (void *adr);
#endif
bit testclear (bit);
bit testset   (bit);
extern unsigned char crol   (unsigned char v, int cnt);
extern unsigned int  irol   (unsigned int  v, int cnt);
extern unsigned long lrol   (unsigned long v, int cnt);
extern unsigned char cror   (unsigned char v, int cnt);
extern unsigned int  iror   (unsigned int  v, int cnt);
extern unsigned long lror   (unsigned long v, int cnt);
extern           int prior  (int v);
extern           int priord (long v);
extern           int pop    (void);
extern          void push   (int v);


extern unsigned int chkfloat  (float x);
extern unsigned int chkdouble (double x);

#ifdef __cplusplus               // EC++
}
#endif

#endif

------------------------------------------------------------------------ 
---
main.h

#ifndef MAIN_H
#define MAIN_H

void delay(unsigned long i);

#endif

------------------------------------------------------------------------ 
---
spi.h

#ifndef SPI_H
#define SPI_H

void init_spi(void);
unsigned char write_spi(unsigned char byte);

#endif
------------------------------------------------------------------------ 
---
display.h

#ifndef _DISPLAY_H_
#define _DISPLAY_H_


//#define LCD_MIRROR         //define to mirror the display
#define LCD_WIDTH            (320)
#define LCD_HEIGHT           (240)
#define RGB(r,g,b)           (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) 
//5 red | 6 green | 5 blue

#define LCD_ID               (0)
#define LCD_DATA             ((0x72)|(LCD_ID<<2))
#define LCD_REGISTER         ((0x70)|(LCD_ID<<2))

#define LCD_RST_DISABLE()    (P1L |= 0x02)
#define LCD_RST_ENABLE()     (P1L &= 0xFD)
#define LCD_CS_DISABLE()     (P1L |= 0x01)
#define LCD_CS_ENABLE()      (P1L &= 0xFE)

//void delay(unsigned long i);
void lcd_clear(unsigned int color);
void draw_rectangle(unsigned int color, unsigned int x0, unsigned int 
y0, unsigned int x1, unsigned int y1);
void draw_rectangle_notfilled(unsigned int color, unsigned int width, 
unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1);
void lcd_draw(unsigned int color);
void lcd_drawstop(void);
void lcd_drawstart(void);
void lcd_area(unsigned int x0, unsigned int y0, unsigned int x1, 
unsigned int y1);
void lcd_cursor(unsigned int x, unsigned int y);
void lcd_cmd(unsigned int reg, unsigned int param);
void lcd_data(unsigned int c);
void lcd_reset(void);


#endif /* _DISPLAY_H_ */

------------------------------------------------------------------------ 
---


Ich hoffe ihr könnt mir sagen, was ich falsch mache..


Danke im Voraus

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.