0% found this document useful (0 votes)
44 views4 pages

TP4 Iso

The document describes code for interfacing with an LCD display using SPI communication. It initializes the LCD and SPI interface, then enters a loop where it continuously reads pixel data from the LCD, calculates the average position of lit pixels, and outputs this to the LCD display.

Uploaded by

anto.aumeunier
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views4 pages

TP4 Iso

The document describes code for interfacing with an LCD display using SPI communication. It initializes the LCD and SPI interface, then enters a loop where it continuously reads pixel data from the LCD, calculates the average position of lit pixels, and outputs this to the LCD display.

Uploaded by

anto.aumeunier
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

// Copyright (c) 2020 Antoine TRAN TAN

// Copyright (c) 2017 Sarah MARSH

#include "mbed.h"
#include "rtos.h"
#include "C12832.h"
#include "c7x10g_font.h"
#include "math.h"

// Using Arduino pin notation


C12832 lcd(D11, D13, D12, D7, D10);

SPI mySPI(PE_6, PE_5, PE_2, PE_4, use_gpio_ssel);

UnbufferedSerial serial(USBTX, USBRX, 19200);

InterruptIn int_pin(PD_12);

EventFlags my_flag;

void mySPI_init();
void ecriture(int,int,int);
void interrupt();

char write_status[2] = {0x00, 0x80};


char read_status[1];
char BufTx[2] = {0x12, 0x80};
char BufRx_data[120];

int16_t pixels[60];

int f = 0;

Thread t1;

float pix = 0.0f;

int cpt = 0;
int i_1 = 0;
int j_1 = 0;
int iopt = 0;
int jopt = 0;
int i_2 = 0;
int j_2 = 0;
int main()
{
mySPI_init();

ecriture(0x01, 0x00, 0x04);


ecriture(0x02, 0x00, 0x02);
ecriture(0x03, 0x00, 0x76);
ecriture(0x04, 0x00, 0x90);
ecriture(0x05, 0x00, 0x08);
ecriture(0x06, 0x00, 0x0F);
ecriture(0xA5, 0x00, 0x88);
ecriture(0xA6, 0x00, 0x88);
ecriture(0xA7, 0x00, 0x88);
ecriture(0xA8, 0x00, 0x88);
ecriture(0xA9, 0x00, 0x88);
ecriture(0xC1, 0x00, 0x02);

ThisThread::sleep_for(100ms);

mySPI.write(write_status, 2, read_status, 1);

// int_pin.fall(&interrupt);

while (1)
{

mySPI.write(BufTx, 2, BufRx_data, 122);

for (int i = 0; i < 61; i++)


{
pixels[i] = (((int16_t)BufRx_data[2 * i]) << 8) |
(int16_t)BufRx_data[(2 * i) + 1];
}

i_2 = 0;
j_2 = 0;

printf("st\n");

for (int i = 0; i < 60; i++)


{
if (pixels[i] > 0)
{
cpt++;
i_1 = (i%10);
j_1 = floor((i + 1)/10);
i_2 = i_2 + i_1;
j_2 = j_2 + j_1;

iopt = i_2/cpt;
jopt = j_2/cpt;

cpt = 0;

for(int i = 0;i<10;i++)
{
for(int j = 0;j<6;j++)
{
if((i == iopt) && (j == jopt))
{
pix = 1.0f;
printf("%4.2f\n", pix);
}
else
{
pix = 0.0f;
printf("%4.2f\n", pix);
}
}
}

}
}

void mySPI_init()
{
mySPI.select();
mySPI.deselect();
mySPI.frequency(100000);
mySPI.format(8, 0);
}

void ecriture(int a,int b,int c)


{
char tab[3] = {a,b,c};
mySPI.write(tab,3,nullptr,0);

void interrupt()
{
my_flag.set(0x01);
}

You might also like