Discussion in "AVR Discussion Forum" started by    roy_mm    Jul 15, 2008.
Tue Jul 15 2008, 12:04 am
#1
i have a nokia 6610/6100 lcd with philips controller. i am interfacing it with atmega32 at 16mhz crystal and jtag disabled. i am using winavr WinAVR 20080430.

this is the code for making a multicolour box at the center of lcd.

please help me and correct this code i write(or say modified from the codes available on internet) ----



#include <avr/io.h>

#include <util/delay.h>


#define F_CPU 16000000UL

#define SPIPORT PORTB
#define SPIDDR DDRB
#define CS 2
#define SDA 3
#define RESET 4
#define CLK 5

#define cbi(reg, bit) (reg&=~(1<<bit))
#define sbi(reg, bit) (reg|= (1<<bit))

#define CS0 cbi(SPIPORT,CS);
#define CS1 sbi(SPIPORT,CS);
#define CLK0 cbi(SPIPORT,CLK);
#define CLK1 sbi(SPIPORT,CLK);
#define SDA0 cbi(SPIPORT,SDA);
#define SDA1 sbi(SPIPORT,SDA);
#define RESET0 cbi(SPIPORT,RESET);
#define RESET1 sbi(SPIPORT,RESET);

#define byte unsigned char
byte n=0;
byte s1,s2;
byte r,g,b;

void sendCMD(byte cmd);
void sendData(byte cmd);
void shiftBits(byte b);
void setPixel(byte r,byte g,byte b);

void waitms(int ms)
{
  int j;
  for (j=0;j<ms;j++)
  {
   _delay_ms(1);
  }
 }

int main (void)
{
  int i;
 
  DDRB = 0xFF;

  SPIDDR=(1<<SDA)|(1<<CLK)|(1<<CS)|(1<<RESET); //Port-Direction Setup
   
//hardware reset

  CS0
  SDA0
  CLK1
 
  RESET1
  RESET0
 
  waitms(10);

  RESET1

  CLK0
  SDA1
  CLK1

  waitms(10);
 
 //Software Reset
  sendCMD(0x01);

 //Sleep Out
  sendCMD(0x11);
 
  //Set Constrast
  sendCMD(0x25);
  sendData(0x3F);

 //Booster ON
  sendCMD(0x03);

  waitms(10);
 
 //Display inversion on
  sendCMD(0x21);

 //Normal display mode
  sendCMD(0x13);

 //Data order
  sendCMD(0xBA);

 //Memory data access control
  sendCMD(0x36);

 //Colour 8 bit
  sendCMD(0x3A);
  sendData(2); 

 // setup color lookup table
  sendCMD(0x2D);
 
  sendData(0);     // red 000 value
  sendData(2);     // red 001 value
  sendData(5);     // red 010 value
  sendData(7);     // red 011 value
  sendData(9);     // red 100 value
  sendData(11);    // red 101 value
  sendData(14);    // red 110 value
  sendData(16);    // red 111 value
  sendData(0);     // green 000 value
  sendData(2);     // green 001 value
  sendData(5);     // green 010 value
  sendData(7);     // green 011 value
  sendData(9);     // green 100 value
  sendData(11);    // green 101 value
  sendData(14);    // green 110 value
  sendData(16);    // green 111 value
  sendData(0);     // blue 000 value
  sendData(6);     // blue 001 value
  sendData(11);    // blue 010 value
  sendData(15);    // blue 011 value

 // nop
  sendCMD(0x00); 
 
 //Display On
  sendCMD(0x29);
 
 //Column Adress Set
  sendCMD(0x2A);
  sendData(0);
  sendData(131);

 //Page Adress Set
  sendCMD(0x2B);
  sendData(0);
  sendData(131);
 
 // write some stuff (background)
  sendCMD(0x2c);
  for (i = 0; i < 18000; i++)
  {
    sendData(28);  // 28 is green
   }
   
   waitms(200);
   
       // draw a multi-colored square in the center of screen
  for (i = 0; i < 4096; i++){
    setPixel(i, (i % 64) + 32, (i / 64) + 32);
  }

  while(1==1)
  {
  // now add here your code
 
  }

}
   
   
 void shiftBits(byte b) {

  CLK0
  if ((b&128)!=0) SDA1 else SDA0
  CLK1

  CLK0
  if ((b&64)!=0) SDA1 else SDA0
  CLK1

  CLK0
  if ((b&32)!=0) SDA1 else SDA0
  CLK1

  CLK0
  if ((b&16)!=0) SDA1 else SDA0
  CLK1

  CLK0
  if ((b&8)!=0) SDA1 else SDA0
  CLK1

  CLK0
  if ((b&4)!=0) SDA1 else SDA0
  CLK1

  CLK0
  if ((b&2)!=0) SDA1 else SDA0
  CLK1

  CLK0
  if ((b&1)!=0) SDA1 else SDA0
  CLK1

}

void setPixel(unsigned char color, unsigned char x, unsigned char y)
{
  x += 2;                  // for some reason starts at 2
  sendCMD(0x2B);   // page start/end ram
  sendData(x);           
  sendData(132);         
  sendCMD(0x2A);   // column start/end ram
  sendData(y);            // for some reason starts at 2
  sendData(131);
  sendCMD(0x2C);    // write some shit
  sendData(color);
}

//send data
void sendData(byte data) {

  CLK0
  SDA1                                                 //1 for param
  CLK1

  shiftBits(data);
}

//send cmd
void sendCMD(byte data) {

  CLK0
  SDA0                                                 //1 for cmd
  CLK1

  shiftBits(data);
}





my configuration is ----


1 VDD 3,3V
2 Reset ------------- PORTB4
3 SDATA ------------ PORTB3
4 SCLK ------------ PORTB5
5 CS ------------ PORTB2
6 VLCD 3,3V
7 NC
8 GND
9 LED-
10 LED+ (6V)
11 NC


[ Edited Tue Jul 15 2008, 12:06 am ]
Tue Jul 15 2008, 10:58 am
#2
everything seems fine to me.. try changing the reset sequence like this..
  CS1
 
  RESET1
  RESET0
 
  waitms(20);

  RESET1
  
  CS0

  waitms(10);


comment the software reset command as hardware reset is sufficient.

Waiting for response.
Wed Jul 16 2008, 02:33 pm
#3
thanks for the suggestion.

is this code produce a box on the screen. also what should be clock setting when calling CS0 and CS1 ?

i also used a 16 mhz crystal, is it sufficient or not ??


[ Edited Wed Jul 16 2008, 02:47 pm ]
Wed Jul 16 2008, 09:01 pm
#4
dont do anything with clock.. leave it as it is..
Sun Aug 03 2008, 01:07 am
#5
hello, i back. i was sick. i made the changes, nothing on lcd.

#include <avr/io.h>

#include <util/delay.h>


#define F_CPU 1000000UL

#define SPIPORT PORTB
#define SPIDDR DDRB
#define CS 2
#define SDA 3
#define RESET 4
#define CLK 5

#define cbi(reg, bit) (reg&=~(1<<bit))
#define sbi(reg, bit) (reg|= (1<<bit))

#define CS0 cbi(SPIPORT,CS);
#define CS1 sbi(SPIPORT,CS);
#define CLK0 cbi(SPIPORT,CLK);
#define CLK1 sbi(SPIPORT,CLK);
#define SDA0 cbi(SPIPORT,SDA);
#define SDA1 sbi(SPIPORT,SDA);
#define RESET0 cbi(SPIPORT,RESET);
#define RESET1 sbi(SPIPORT,RESET);

#define byte unsigned char
byte n=0;
byte s1,s2;
byte r,g,b;

void sendCMD(byte cmd);
void sendData(byte cmd);
void shiftBits(byte b);
void setPixel(byte r,byte g,byte b);

void waitms(int ms)
{
  int j;
  for (j=0;j<ms;j++)
  {
   _delay_ms(1);
  }
 }

int main (void)
{
  int i;
 
  DDRB = 0xFF;

  SPIDDR=(1<<SDA)|(1<<CLK)|(1<<CS)|(1<<RESET); //Port-Direction Setup
   
//hardware reset

  CS1  
 
  RESET1
  RESET0
 
  waitms(10);

  RESET1

  CS0
  
  waitms(10);
 
 //Software Reset
  sendCMD(0x01);

 //Sleep Out
  sendCMD(0x11);
 
  //Set Constrast
  sendCMD(0x25);
  sendData(0x3F);

 //Booster ON
  sendCMD(0x03);

  waitms(10);
 
 //Display inversion on
  sendCMD(0x21);

 //Normal display mode
  sendCMD(0x13);

 //Data order
  sendCMD(0xBA);

 //Memory data access control
  sendCMD(0x36);

 //Colour 8 bit
  sendCMD(0x3A);
  sendData(2);

 // setup color lookup table
  sendCMD(0x2D);
 
  sendData(0);     // red 000 value
  sendData(2);     // red 001 value
  sendData(5);     // red 010 value
  sendData(7);     // red 011 value
  sendData(9);     // red 100 value
  sendData(11);    // red 101 value
  sendData(14);    // red 110 value
  sendData(16);    // red 111 value
  sendData(0);     // green 000 value
  sendData(2);     // green 001 value
  sendData(5);     // green 010 value
  sendData(7);     // green 011 value
  sendData(9);     // green 100 value
  sendData(11);    // green 101 value
  sendData(14);    // green 110 value
  sendData(16);    // green 111 value
  sendData(0);     // blue 000 value
  sendData(6);     // blue 001 value
  sendData(11);    // blue 010 value
  sendData(15);    // blue 011 value

 // nop
  sendCMD(0x00);
 
 //Display On
  sendCMD(0x29);
 
 //Column Adress Set
  sendCMD(0x2A);
  sendData(0);
  sendData(131);

 //Page Adress Set
  sendCMD(0x2B);
  sendData(0);
  sendData(131);
 
 // write some stuff (background)
  sendCMD(0x2c);
  for (i = 0; i < 18000; i++)
  {
    sendData(28);  // 28 is green
   }
   
   waitms(200);
   
       // draw a multi-colored square in the center of screen
  for (i = 0; i < 4096; i++){
    setPixel(i, (i % 64) + 32, (i / 64) + 32);
  }

  while(1==1)
  {
  // now add here your code
 
  }

}
   
   
 void shiftBits(byte b) {

  CLK0
  if((b&128)!=0) 
	SDA1 
  else
	SDA0
  CLK1

  CLK0
  if((b&64)!=0)
	SDA1 
  else
	SDA0
  CLK1

  CLK0
  if((b&32)!=0)
	SDA1
  else
	SDA0
  CLK1

  CLK0
  if((b&16)!=0)
	SDA1
  else
	SDA0
  CLK1

  CLK0
  if((b&8)!=0)
	SDA1
  else
	SDA0
  CLK1

  CLK0
  if((b&4)!=0)
	SDA1
  else
	SDA0
  CLK1

  CLK0
  if((b&2)!=0)
	SDA1
  else
	SDA0
  CLK1

  CLK0
  if((b&1)!=0)
	SDA1
  else
	SDA0
  CLK1

}

void setPixel(unsigned char color, unsigned char x, unsigned char y)
{
  x += 2;                  // for some reason starts at 2
  sendCMD(0x2B);   // page start/end ram
  sendData(x);          
  sendData(132);        
  sendCMD(0x2A);   // column start/end ram
  sendData(y);            // for some reason starts at 2
  sendData(131);
  sendCMD(0x2C);    // write some shit
  sendData(color);
}

//send data
void sendData(byte data) {

  CLK0
  SDA1                                                 //1 for param
  CLK1

  shiftBits(data);
}

//send cmd
void sendCMD(byte data) {

  CLK0
  SDA0                                                 //1 for cmd
  CLK1

  shiftBits(data);
}

i am using a new atmega32 with clock 1 mhz.
Mon Aug 04 2008, 09:01 pm
#6
is the lcd working i know silly question..

also do not forget to disable watchdog (if enabled by default)

check the pins of controller on CRO. see if everything is working fine..
Wed Aug 06 2008, 02:16 pm
#7
to check lcd is not possible because i soldered wires to lcd.
i dont disable watchdog. why it should be disabled ? i m using atmega32 at 1mhz only. can u provide some tutorial(like ur charcter lcd tutorial which is great) ? i dont mind if it is for other uc.

also i dont hav osilloscope, etc so that is not an option for me.
is there any nokia 6610 lcd plugin for proteus ?


[ Edited Wed Aug 06 2008, 02:22 pm ]
Wed Aug 06 2008, 08:56 pm
#8
well so you have to remember that if you are using WDT, then you need to reset the watchdog timer in timely manner otherwise it will reset your controller.

so try running your program without WDT.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

MichaelGot
Tue May 14 2024, 04:08 pm
FrankTrelm
Tue May 14 2024, 10:39 am
BillyTum
Tue May 14 2024, 09:08 am
Loganbag
Tue May 14 2024, 04:05 am
MichaelMog
Tue May 14 2024, 03:58 am
ThomasGaxaW
Mon May 13 2024, 05:33 pm
RobertInfup
Mon May 13 2024, 04:28 pm
Joshuatem
Mon May 13 2024, 08:30 am