SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on the software and hardware for Atmel's STK standard.
By roy_mm
#53496
i have a nokia 6610 lcd with philips controller. i am interfacing it with atmega32 at 1mhz 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) ----
Code: Select all

#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

  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 ****
  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+ (7V)
11 NC
By roy_mm
#53715
please help guys. i need it, plz
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]