vailant
Newbie level 5
Im trying to do a integration of analogue sensor to OLED(uOLED-96-G1) and microcontroller(8051F226) using Silicon Labolatories.
But i got no idea how to do it. i've attach a paint and a note pad to explain more in detail. please do take a look. what i'm able to do now is only to display the line and circle. please do help me with the programming and where(which pin) should i input the analog signal... Thank you!
/////////////////////////////////////
// Generated Initialization File //
/////////////////////////////////////
#include "C8051F200.h"
#include "GSGCdef.h"
//#include "dos.h"
//#include "conio.h"
// Peripheral specific initialization functions,
// Called from the Init_Device() function
sbit LED=P2^4;
sbit SWITCH=P2^5;
int ttt[10];
int qqq;
int aaa;
int x=1;
unsigned char d_receive;
unsigned char Receive();
void SendChar(unsigned char b);
void OLED_DrawLine(char cmd ,int x1, int y1, int x2, int y2,int color1,int color2);
void OLED_DrawCircle(char cmd ,int x3, int y3, int radius, int color3,int color4);
void delay(int value);
void pensize(char cmd,char size);
int x1=0x00;
int y1=0x20;
int x2=0x60;
int y2=0x20;
int color1=0xFF;
int color2=0xFF;
int x3=0x10;
int y3=0x30;
int radius = 0x02;
int color3=0xF8;
int color4=0x00;
void pensize(char cmd,char size)
{
SendChar(cmd);
SendChar(size);
}
void OLED_DrawLine(char cmd ,int x1, int y1, int x2, int y2,int color1,int color2)
{
SendChar(cmd);
SendChar(x1);
SendChar(y1);
SendChar(x2);
SendChar(y2);
SendChar(color1);
SendChar(color2);
}
void OLED_DrawCircle(char cmd ,int x3, int y3, radius, int color3,int color4)
{
SendChar(cmd);
SendChar(x3);
SendChar(y3);
SendChar(radius);
SendChar(color3);
SendChar(color4);
}
void Timer_Init()
{
CKCON = 0x30;
TMOD = 0x20;
TH1 = 0xFA;
T2CON = 0x34;
RCAP2L = 0xFA; //baud rate for 57600bps
RCAP2H = 0xFF;
}
void UART_Init()
{
PCON = 0x80;
SCON = 0x70;
}
void Port_IO_Init()
{
// P0.0 - TX (UART), Push-Pull Digital
// P0.1 - RX (UART), Push-Pull Digital
// P0.2 - Unassigned, Open-Drain Digital
// P0.3 - Unassigned, Open-Drain Digital
// P0.4 - Unassigned, Open-Drain Digital
// P0.5 - Unassigned, Open-Drain Digital
// P0.6 - Unassigned, Open-Drain Digital
// P0.7 - Unassigned, Open-Drain Digital
// P1.0 - Unassigned, Open-Drain Digital
// P1.1 - Unassigned, Open-Drain Digital
// P1.2 - Unassigned, Open-Drain Digital
// P1.3 - Unassigned, Open-Drain Digital
// P1.4 - Unassigned, Open-Drain Digital
// P1.5 - Unassigned, Open-Drain Digital
// P1.6 - Unassigned, Open-Drain Digital
// P1.7 - Unassigned, Open-Drain Digital
// P2.0 - Unassigned, Open-Drain Digital
// P2.1 - Unassigned, Open-Drain Digital
// P2.2 - Unassigned, Open-Drain Digital
// P2.3 - Unassigned, Open-Drain Digital
// P2.4 - Unassigned, Open-Drain Digital
// P2.5 - Unassigned, Open-Drain Digital
// P2.6 - Unassigned, Open-Drain Digital
// P2.7 - Unassigned, Open-Drain Digital
PRT0MX = 0x01;
PRT0CF = 0x03;
PRT2CF = 0x10;
}
void Oscillator_Init()
{
int i = 0;
OSCXCN = 0x67;
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCXCN & 0x80) == 0);
OSCICN = 0x08;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
Timer_Init();
UART_Init();
Port_IO_Init();
Oscillator_Init();
}
unsigned char Receive()
{
while(RI!=1);
RI=0;
qqq++;
d_receive=SBUF;
//RI=0;
}
void SendChar(unsigned char b)
{
SBUF=b;
//delay(1);
while(TI!=1);
TI=0;
}
void delay (int value)
{
int a,b;
for (a=0; a<value; a++)
{
for (b=0; b<20000;b++)
{
}
}
}
void Display(void)
{
pensize(0x70,0x00);
OLED_DrawCircle(0x43,x3,y3,radius,color3,color4); //display circle
Receive();
if(d_receive!=0x06) //not equal to acknowledge
{
OLED_DrawCircle(0x43,x3,y3,radius,color3,color4);
Receive();
}
Receive();
}
void main()
{
Init_Device();
TI=0;
RI=0;
x=1;
//qqq=0;
//aaa=0;
SendChar(GSGC_AUTOBAUD);
Receive();
SendChar(GSGC_CLS);
Receive();
OLED_DrawLine(0x4C,x1,y1,x2,y2,color1,color2); //display rectangle
if(d_receive!=0x06) //not equal to acknowledge
{
OLED_DrawLine(0x4C,x1,y1,x2,y2,color1,color2);
Receive();
}
while(1)
{
Display();
delay(3);
}
}
Added after 3 hours 9 minutes:
can anyone please help me? =(
But i got no idea how to do it. i've attach a paint and a note pad to explain more in detail. please do take a look. what i'm able to do now is only to display the line and circle. please do help me with the programming and where(which pin) should i input the analog signal... Thank you!
/////////////////////////////////////
// Generated Initialization File //
/////////////////////////////////////
#include "C8051F200.h"
#include "GSGCdef.h"
//#include "dos.h"
//#include "conio.h"
// Peripheral specific initialization functions,
// Called from the Init_Device() function
sbit LED=P2^4;
sbit SWITCH=P2^5;
int ttt[10];
int qqq;
int aaa;
int x=1;
unsigned char d_receive;
unsigned char Receive();
void SendChar(unsigned char b);
void OLED_DrawLine(char cmd ,int x1, int y1, int x2, int y2,int color1,int color2);
void OLED_DrawCircle(char cmd ,int x3, int y3, int radius, int color3,int color4);
void delay(int value);
void pensize(char cmd,char size);
int x1=0x00;
int y1=0x20;
int x2=0x60;
int y2=0x20;
int color1=0xFF;
int color2=0xFF;
int x3=0x10;
int y3=0x30;
int radius = 0x02;
int color3=0xF8;
int color4=0x00;
void pensize(char cmd,char size)
{
SendChar(cmd);
SendChar(size);
}
void OLED_DrawLine(char cmd ,int x1, int y1, int x2, int y2,int color1,int color2)
{
SendChar(cmd);
SendChar(x1);
SendChar(y1);
SendChar(x2);
SendChar(y2);
SendChar(color1);
SendChar(color2);
}
void OLED_DrawCircle(char cmd ,int x3, int y3, radius, int color3,int color4)
{
SendChar(cmd);
SendChar(x3);
SendChar(y3);
SendChar(radius);
SendChar(color3);
SendChar(color4);
}
void Timer_Init()
{
CKCON = 0x30;
TMOD = 0x20;
TH1 = 0xFA;
T2CON = 0x34;
RCAP2L = 0xFA; //baud rate for 57600bps
RCAP2H = 0xFF;
}
void UART_Init()
{
PCON = 0x80;
SCON = 0x70;
}
void Port_IO_Init()
{
// P0.0 - TX (UART), Push-Pull Digital
// P0.1 - RX (UART), Push-Pull Digital
// P0.2 - Unassigned, Open-Drain Digital
// P0.3 - Unassigned, Open-Drain Digital
// P0.4 - Unassigned, Open-Drain Digital
// P0.5 - Unassigned, Open-Drain Digital
// P0.6 - Unassigned, Open-Drain Digital
// P0.7 - Unassigned, Open-Drain Digital
// P1.0 - Unassigned, Open-Drain Digital
// P1.1 - Unassigned, Open-Drain Digital
// P1.2 - Unassigned, Open-Drain Digital
// P1.3 - Unassigned, Open-Drain Digital
// P1.4 - Unassigned, Open-Drain Digital
// P1.5 - Unassigned, Open-Drain Digital
// P1.6 - Unassigned, Open-Drain Digital
// P1.7 - Unassigned, Open-Drain Digital
// P2.0 - Unassigned, Open-Drain Digital
// P2.1 - Unassigned, Open-Drain Digital
// P2.2 - Unassigned, Open-Drain Digital
// P2.3 - Unassigned, Open-Drain Digital
// P2.4 - Unassigned, Open-Drain Digital
// P2.5 - Unassigned, Open-Drain Digital
// P2.6 - Unassigned, Open-Drain Digital
// P2.7 - Unassigned, Open-Drain Digital
PRT0MX = 0x01;
PRT0CF = 0x03;
PRT2CF = 0x10;
}
void Oscillator_Init()
{
int i = 0;
OSCXCN = 0x67;
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCXCN & 0x80) == 0);
OSCICN = 0x08;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
Timer_Init();
UART_Init();
Port_IO_Init();
Oscillator_Init();
}
unsigned char Receive()
{
while(RI!=1);
RI=0;
qqq++;
d_receive=SBUF;
//RI=0;
}
void SendChar(unsigned char b)
{
SBUF=b;
//delay(1);
while(TI!=1);
TI=0;
}
void delay (int value)
{
int a,b;
for (a=0; a<value; a++)
{
for (b=0; b<20000;b++)
{
}
}
}
void Display(void)
{
pensize(0x70,0x00);
OLED_DrawCircle(0x43,x3,y3,radius,color3,color4); //display circle
Receive();
if(d_receive!=0x06) //not equal to acknowledge
{
OLED_DrawCircle(0x43,x3,y3,radius,color3,color4);
Receive();
}
Receive();
}
void main()
{
Init_Device();
TI=0;
RI=0;
x=1;
//qqq=0;
//aaa=0;
SendChar(GSGC_AUTOBAUD);
Receive();
SendChar(GSGC_CLS);
Receive();
OLED_DrawLine(0x4C,x1,y1,x2,y2,color1,color2); //display rectangle
if(d_receive!=0x06) //not equal to acknowledge
{
OLED_DrawLine(0x4C,x1,y1,x2,y2,color1,color2);
Receive();
}
while(1)
{
Display();
delay(3);
}
}
Added after 3 hours 9 minutes:
can anyone please help me? =(