Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - bsoyer

Pages: [1]
1
solved!!! After trying lots of combinations, I decided to comment out the initialization code step by step, I noticed that when I removed the master config part (below) from the init code the problem is solved.

// Set Master Config
   spi_data[0]=0xAD;
   spi_data[1]=0x00;
   SPI_Write(2,&spi_data[0],0);

2
Hello Paul,
Thanks for the quick reply.I double check my initialization sequence and SPI timing, I noticed that SPI timing is alittle bit faster than controller's expected freq. I fixed it and in order to simplify my code I decide to draw a rectangle but again I get the same result (dark-yellow columns occur above and below). I am using PIC32MX795F512L and my code is below

/* Adds support for PIC32 Peripheral library functions and macros */
#include "plib.h"
#include "proc/p32mx795f512l.h"

extern char ASCII[][5];
extern char logo[][32];

// Configuration Bits
#pragma config FNOSC    = PRIPLL        // Oscillator Selection
#pragma config FPLLIDIV = DIV_5         // PLL Input Divider (PIC32 Starter Kit: use divide by 2 only)
#pragma config FPLLMUL  = MUL_16        // PLL Multiplier
#pragma config FPLLODIV = DIV_1         // PLL Output Divider
#pragma config FPBDIV   = DIV_1         // Peripheral Clock divisor
#pragma config FWDTEN   = OFF           // Watchdog Timer
#pragma config WDTPS    = PS1           // Watchdog Timer Postscale
#pragma config FCKSM    = CSDCMD        // Clock Switching & Fail Safe Clock Monitor
#pragma config OSCIOFNC = OFF           // CLKO Enable
#pragma config POSCMOD  = XT            // Primary Oscillator
#pragma config IESO     = OFF           // Internal/External Switch-over
#pragma config FSOSCEN  = OFF           // Secondary Oscillator Enable
#pragma config CP       = OFF           // Code Protect
#pragma config BWP      = OFF           // Boot Flash Write Protect
#pragma config PWP      = OFF           // Program Flash Write Protect
#pragma config ICESEL   = ICS_PGx1      // ICE/ICD Comm Channel Select
#pragma config DEBUG    = ON           // Debugger Disabled for Starter Kit

// application defines
#define SYS_FREQ      (80000000)

// prototype
void DelayMs(unsigned int);
void DelayUs(unsigned int);
void SPI_1();
void LCD_Initialization();
void LCD_Function();
void lcd_create_rect(int st_row,int st_col,int end_row,int end_col, int color);
void lcd_set_col_addr(int start, int end);
void lcd_set_row_addr(int start, int end);
void LCD_clear();

char spi_data[1048];
char last_row = 56;
char last_col = 0;
//  blink_leds application code
int main(void)
{
      SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
   LCD_Function();
   return 0;
}

/******************************************************************************
*   DelayMs()
*
*   This functions provides a software millisecond delay
******************************************************************************/
void DelayMs(unsigned int msec)
{
   unsigned int tWait, tStart;
      
    tWait=(SYS_FREQ/2000)*msec;
    tStart=ReadCoreTimer();
    while((ReadCoreTimer()-tStart)<tWait);      // wait for the time to pass
   return;
}
void DelayUs(unsigned int usec)
{
   unsigned int tWait, tStart;
      
    tWait=(SYS_FREQ/2000000)*usec;
    tStart=ReadCoreTimer();
    while((ReadCoreTimer()-tStart)<tWait);      // wait for the time to pass
   return;
}
/******************************************************************************/
void SPI_1()
{

   int rData;
   IEC0CLR=0x03800000; // disable all interrupts
   SPI1CON = 0; // Stops and resets the SPI1.
   rData=SPI1BUF; // clears the receive buffer
   IFS0CLR=0x03800000; // clear any existing event
   IPC5CLR=0x1f000000; // clear the priority
   IPC5SET=0x0d000000; // Set IPL=3, Subpriority 1
   IEC0SET=0x03800000; // Enable RX, TX and Error interrupts
   SPI1BRG=19; // FPB/2(baud+1) => 80Mhz / 2*20 = 2 Mhz clock frequency
   SPI1STATCLR=0x40; // clear the Overflow
   SPI1CON=0x8260; // SPI ON, 8 bits transfer, SMP=1, Master mode
}
/******************************************************************************/
void SPI_Write(int byte_count, char* data, int dataOrComm)
{
   int count;
   // give data or command
   LATCbits.LATC2=dataOrComm;
   // assert CS
   LATDbits.LATD9=0;
   // wait till spi is busy
   for (count=0;count<byte_count;count++)
   {
      SPI1BUF=data[count];
      while (SPI1STATbits.SPIBUSY==1);
   }
   // deassert CS
   LATDbits.LATD9=1;
   DelayMs(1);
}

void LCD_Initialization()
{   
   int i,j;   
      
   //Set display off
   spi_data[0]=0xAE;
   SPI_Write(1,&spi_data[0],0);

   //Set Display Clock
   spi_data[0]=0xB3;
   spi_data[1]=0x91;
   SPI_Write(2,&spi_data[0],0);

   //Set Multiplex Ratio
   spi_data[0]=0xA8;
   spi_data[1]=0x3F;
   SPI_Write(2,&spi_data[0],0);
   
   //Set Display Offset
   spi_data[0]=0xA2;
   spi_data[1]=0x4C;//0x44;
   SPI_Write(2,&spi_data[0],0);

   // Set Start Line
   spi_data[0]=0xA1;
   spi_data[1]=0x00;
   SPI_Write(2,&spi_data[0],0);

   // Set Master Config
   spi_data[0]=0xAD;
   spi_data[1]=0x00;
   SPI_Write(2,&spi_data[0],0);

   // Set ReMap
   spi_data[0]=0xA0;
   spi_data[1]=0x50;//0x44;
   SPI_Write(2,&spi_data[0],0);

   // Set Current Range
   spi_data[0]=0x86;   
   SPI_Write(1,&spi_data[0],0);

   // Set Gray Scale
   spi_data[0]=0xB8;
   spi_data[1]=0x01;
   spi_data[2]=0x11;
   spi_data[3]=0x22;
   spi_data[4]=0x32;
   spi_data[5]=0x43;
   spi_data[6]=0x54;
   spi_data[7]=0x65;
   spi_data[8]=0x76;
   SPI_Write(9,&spi_data[0],0);

   // Set Contrast
   spi_data[0]=0x81;
   spi_data[1]=0x7F;
   SPI_Write(2,&spi_data[0],0);

   //Set Frame Frequency
   spi_data[0]=0xB2;
   spi_data[1]=0x51;
   SPI_Write(2,&spi_data[0],0);   

   //Set Phase Length
   spi_data[0]=0xB1;
   spi_data[1]=0x55;
   SPI_Write(2,&spi_data[0],0);

   // Set Precharge Voltage
   spi_data[0]=0xBC;
   spi_data[1]=0x10;
   SPI_Write(2,&spi_data[0],0);

   // Set Precharge Compensation
   spi_data[0]=0xB4;
   spi_data[1]=0x02;
   SPI_Write(2,&spi_data[0],0);

   //Enable Pre-Charge Compensation
   spi_data[0]=0xB0;
   spi_data[1]=0x28;
   SPI_Write(2,&spi_data[0],0);

   // Set High Voltage Level of COM Pin
   spi_data[0]=0xBE;
   spi_data[1]=0x1C;
   SPI_Write(2,&spi_data[0],0);

   // Set Low Voltage Level of SEG Pin
   spi_data[0]=0xBF;
   spi_data[1]=0x0D;
   SPI_Write(2,&spi_data[0],0);   
   
   // Set Display Mode
   spi_data[0]=0xA4;
   SPI_Write(1, &spi_data[0],0);

   // Clear Screen
   LCD_clear();
   // Set Display on
   spi_data[0]=0xAF;
   SPI_Write(1,&spi_data[0],0);
}
void LCD_clear()
{
   char i,j;
   lcd_set_row_addr(0,63);
   lcd_set_col_addr(0,127);
   for (i=0;i<64;i++)
   {
      for ( j=0;j<64;j++)
      {
      spi_data[0]=0x00;
      SPI_Write(1,&spi_data[0],1);
      }
   }
   return;   
}
void LCD_Function()
{
   char spi_data[1048];
   char start_row = 0x00;
   char start_col = 0x00;
    char character = 0x20;
   // RESET
   TRISCbits.TRISC3=0;
   LATCbits.LATC3=0;
   DelayMs(50);
   LATCbits.LATC3=1;
   // Set D/C bit as output
   TRISCbits.TRISC2=0;
   //Set CS bit as output
   TRISDbits.TRISD9=0;
   LATDbits.LATD9=1;   
   
   SPI_1();
   LCD_Initialization();
   
//   Enable Rectangle engine
   spi_data[0]=0x23;
   spi_data[1]=0x03;
   SPI_Write(2,&spi_data[0],0);

   lcd_create_rect(10,10,24,30,0xFF);
}

void lcd_create_rect(int st_row,int st_col,int end_row,int end_col, int color)
{
   spi_data[0]=0x24;
   spi_data[1]=st_col;
   spi_data[2]=st_row;
   spi_data[3]=end_col;
   spi_data[4]=end_row;
   spi_data[5]=color;
   SPI_Write(6,&spi_data[0],0);
}

void lcd_set_col_addr(int start, int end)
{
   spi_data[0]=0x15;
   spi_data[1]=start;
   spi_data[2]=end;
   SPI_Write(3,&spi_data[0],0);
}
void lcd_set_row_addr(int start, int end)
{
   spi_data[0]=0x75;
   spi_data[1]=start;
   spi_data[2]=end;
   SPI_Write(3,&spi_data[0],0);
}


3
OLEDs / NHD-2.7-12864UCY3 yellow columns occur under ascii characters
« on: April 01, 2015, 02:43:44 PM »
Hello I am using NHD-2.7-12864UCY3 in serial mode. I write lcd init functions with the help of Lcd and its controller datasheet, example program code. I am able to print ascii characters but under every character there occurs a dark yellow column (as seen in the picture) and I can't handle these columns. Do you have any idea the cause of the columns? I can send my code also
thanks alot.

Pages: [1]