This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How do I convert c code

Other Parts Discussed in Thread: ENERGIA

hey there;

this code fast fourier transform LCD embedded project.

In this way the linear ccd


#include <energia.h>

#include "driverlib/adc.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include <stdlib.h>

/*
--------------------------------------------------------------------
Lecture du CCD monoligne SONY ILX 511 avec une carte LaunchPad Tiva C séries TM4C123G

Programme Open source de Jean Brunet.
Mis en ligne en février 2014.

Ce programme peut être copié, modifié ou adapté pour d'autres CCD
Ce programme ne peut être vendu

Ce programme demande Energia pour programmer le TM4C123G
Energia reprend la plateforme Arduino ce qui permet de programmer facilement l'ARM
Au menu Tools->Board choisir LaunchPad (Tiva C)W/ TMC7123G (80Mhz)


LaunchPad haritası Tiva C serisi TM4C123G ile tek satır CCD SONY 511 ILX Playing

Açık kaynak programı Jean Brunet.
Şubat 2014 yılında başlatılan.

Bu program, kopyalanamaz değiştirilmiş ya da diğer CCD adapte edilebilir
Bu program satılamaz

Bu program TM4C123G programlamak için Energia sorar
Energia kolayca ARM programlamasını sağlar Arduino platformu kullanır
Araçlar-> Yönetim Kurulu seçin LaunchPad (Tiva C) W / TMC7123G (80MHz)
--------------------------------------------------------------------*/

#define CLK PB_0
#define ROG PB_1
#define SYNCHRO RED_LED

#define uchar unsigned char

uint8_t ROGhCLOCKh = 0x3 ;
uint8_t ROGhCLOCKb = 0x1 ;
uint8_t ROGbCLOCKh = 0x2 ;

// Organisation des pixels du CCD Sony ILX 511.
// Sony CCD Organizasyon İLX 511 piksel.
// 32 dummy, 18 blacks, 2048 pxels, 6 dummy = 2086 au total
// 32 kukla, 18 siyahlar, 2048, 6 kukla = 2086 toplam pxels

uint8_t mode;
uint nbvues;
uint pose;
uint interpose;
uchar buzz;
uchar ch[16]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,0x45,0x46};
uint16_t buffer_ccd[2048]; // buffer d'une ligne
// Bir çizgi tampon
boolean ima = false;


void setup() {
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0);

ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 1);

GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, CLK|ROG);
pinMode(SYNCHRO, OUTPUT); // Optionnel, pour des applications demandant le moment précis du début et de la fin de lecture du CCD
// İsteğe bağlı, başlangıç hassas zaman, CCD okuma ucunu gerektiren uygulamalarda
// Allume la led, possibilité de choisir une autre sortie.
// LED ışıklar, başka bir çıkış seçebilirsiniz.
Serial.begin(307200); // vitesse de transmission USB
// USB aktarım hızı

}

/*-----------------------------------------------------------
Boucle du programme
Program loop
Program döngü
Program döngü
------------------------------------------------------------*/

void loop() {
ReadBufferUSB();
command();
}

/*-----------------------------------------------------------
Lecture d'un ordre du PC transmis par l'USB
Read USB
USB ile PC'den gönderilen sipariş Playing
USB oku
------------------------------------------------------------*/

void command()
{
// lecture d'un ordre du PC
// PC oynatma sırası
uchar j=0;
uint l;

if(mode == 1) // Focus
{

interpose = 100; // intervalle de 100 ms entre chaque trame
// Her çerçeve arasında 100 ms aralığı
ClearCCD();
while(mode !=0)
{
// focus
ClearCCD();
integrationtime(pose);
WriteBufferUSB(0); // envoi vers USB USB göndermek
delay(interpose);
if (Serial.available() > 0)
{
ReadBufferUSB(); // si mode = 0 fin de focus
// Mod odak 0 ucunu = eğer
}
}
}
if(mode == 2) // monovue sur 12 bits
// 12-bit mono görünümleri
{
ClearCCD();
integrationtime(pose);
WriteBufferUSB(0);
mode = 0;
}

if(mode == 3)
{
clearbuf();
// 16 vues pour numérisation sur 16 bits.
// 16-bit sayısallaştırma için 16 çekim.
interpose = 0;
for(l=0;l<16;l++)
{
ClearCCD();
integrationtime(pose);
delay(interpose);
}
WriteBufferUSB(l); // Put BufferUSB
// Put BufferUSB Put USB Tampon
mode = 0;
}
}

/*-----------------------------------------------------------
Vidage du buffer CCD
Clear memory CCD buffer
CCD tampon dökümü
Temizle bellek tampon CCD
------------------------------------------------------------*/

void clearbuf()
{
for(int n=0;n<2048;n++)
{
buffer_ccd[n]=0;
}
}

/*-----------------------------------------------------------
Envoi vers le PC des pixels numérisés
Write USB with buffer_ccd
Gönderme PC piksel taranan
USB buffer_ccd ile yaz
------------------------------------------------------------*/

void WriteBufferUSB(int l)
{
char buf[4];
if(mode == 3)
{
Serial.print("C"); // cumul sur 16 bits
// kümülatif 16-bit
}
else
{
Serial.print("L"); // envoi ligne sur 10 bits
// Gönder satır 10-bit
}

// envoi du buffer image
// resim tampon gönderme
for(int n=0;n<2048;n++)
{
conv_hexa(buffer_ccd[n],4,buf);
Serial.print(buf);
}
Serial.print("Z"); // et Z, fin de trame
// ve Z çerçeve sonu
}

/*-----------------------------------------------------------
Conversion d'un entier en Hexa dans une chaine de caractères.
dat = nombre, *Bstr = chaine, n = nombre de caractères hexa
Convert Int -> hexa
Bir dizesinde tüm Hexa dönüştürme.
dat = sayı * = Bstr zinciri, n = sayı onaltılık karakter
Int dönüştürme -> onaltılık
------------------------------------------------------------*/

void conv_hexa(uint dat, uchar n, char *Bstr)
{
uchar *pt;
uchar i,j,k;
pt=ch;
i=0;
j=n-1;
while (i!=n)
{
k= (uchar)dat & 0x0F;
*(Bstr+j--) = *(pt+k);
dat = dat >> 4;
i++;
}
*(Bstr+n) = '\0';
}

/*-----------------------------------------------------------
Réception du port USB et décodage des données
Read USB
USB alıcı liman ve veri çözme
USB oku
------------------------------------------------------------*/

void ReadBufferUSB()
{
// trame de 8 octets selon le protocole.
// Mode (2 octets) + temps de pose (4 octets) + fin de trame (2 octets)
// çerçeve protokolüne göre 8 bayt.
// Moda (2 byte) + pozlama süresi (4 bayt) + çerçevenin sonuna (2 bayt)
uchar j=0,Rusb[10];
uchar k;

while(j!=9) // la chaine se termine par /0
// zincir / '0 ile biter
{
if (Serial.available() > 0)
{
k=Serial.read();
Rusb[j] = k - 0x30;
j++;
}
}

// teste si fin de trame correcte
// Doğru çerçeve sonu olmadığını testleri
if(Rusb[6] == 22 && Rusb[7] == 22)
{
mode = (uchar)(Rusb[1] + Rusb[0]*16);
pose= (((((Rusb[2]*16)+Rusb[3])*16)+Rusb[4])*16)+Rusb[5];
}
else
{
// Serial.println("Transmission error ! ");
}
}

/*-----------------------------------------------------------
Boucle de temporisation
Tempo
Zamanlama döngü
tempo
------------------------------------------------------------*/

void tempo_mic(int cpt)
{
int i;
for(i=0;i<cpt;i++)
{
asm ( "nop" ); //
}
}

/*-----------------------------------------------------------
Lecture et numérisation du CCD
Read CCD chip
Okuma ve tarama CCD
CCD çipi Oku
------------------------------------------------------------*/

void integrationtime(uint temps)
{
uint i;

delay(temps);
// lecture du CCD et stockage dans mémoire
// CCD ve depolama belleği okuma
LineDown();

dummypixel(32); // dont 18 black pixels depuis pixel 14.
// piksel 14 18 siyah pikseller dahil.
for(i=0;i<2048;i++)
{
ReadPixel(i);
}
dummypixel(6);
}

/*-----------------------------------------------------------
Nettoyage du CCD avant la lecture
Clear CCD chip
Okumadan önce CCD Temizleme
Temizle CCD çipi
------------------------------------------------------------*/

void ClearCCD(void)
{
// 10 lecture rapides sans numérisation pour nettoyer le capteur des charges.
//Tarama olmadan 10 hızlı okuma yük sensörü temizlemek için.
int j;
for(j=0;j<10;j++)
{
LineDown();
dummypixel(2086);
}
}

/*-----------------------------------------------------------
Descente d'une ligne dans le registre pour accéder aux pixels
Down Line on CCD chip
Piksel erişmek için kayıt içinde bir satır aşağı
CCD çipi üzerinde Hattı aşağı
------------------------------------------------------------*/

void LineDown(void)
{
// front positif pozitif kenar
GPIOPinWrite(GPIO_PORTB_BASE, CLK|ROG, ROGhCLOCKb);
GPIOPinWrite(GPIO_PORTB_BASE, CLK|ROG, ROGhCLOCKh);

// 3 usec
delay(3);
GPIOPinWrite(GPIO_PORTB_BASE, CLK|ROG, ROGbCLOCKh);
// tempo 5 usec
delay(5);
GPIOPinWrite(GPIO_PORTB_BASE, CLK|ROG, ROGhCLOCKh);
// 3 u sec
delay(3);
GPIOPinWrite(GPIO_PORTB_BASE, CLK|ROG, ROGhCLOCKb);
tempo_mic(5);
}


/*-----------------------------------------------------------
Sortie des pixels inutiles
Output dummy pixels
Çıkış gereksiz piksel
Çıkış kukla piksel
------------------------------------------------------------*/

void dummypixel(int nb)
{
int i;

for(i=0;i<nb;i++)
{
GPIOPinWrite(GPIO_PORTB_BASE, CLK|ROG, ROGhCLOCKh);
tempo_mic(10);
asm ( "nop" );
asm ( "nop" );
asm ( "nop" );
asm ( "nop" );
GPIOPinWrite(GPIO_PORTB_BASE, CLK|ROG, ROGhCLOCKb);
tempo_mic(10);
asm ( "nop" );
}
}

/*-----------------------------------------------------------
Conversion A/N des pixels
Pixels conversion
A / D dönüştürme piksel
dönüşüm piksel
------------------------------------------------------------*/

uint16_t analogRead0()
{
uint32_t *mesure;
uint32_t data;

mesure=&data;

ADCIntClear(ADC0_BASE, 1);
ADCProcessorTrigger(ADC0_BASE, 1);

while(!ADCIntStatus(ADC0_BASE, 1, false))
{
}
ADCSequenceDataGet(ADC0_BASE, 1, mesure);

return (uint16_t)*mesure;
}

/*-----------------------------------------------------------
Mise en tableau des pixels numérisés
Read pixels on CCD chip and store in memory
Sayısallaştırılmış piksel tabulation
Piksel CCD çipi okuyun ve bellekte saklamak
------------------------------------------------------------*/

void ReadPixel(uint inc)
{
GPIOPinWrite(GPIO_PORTB_BASE, CLK|ROG, ROGhCLOCKh);

tempo_mic(15); // pour stabilisation signal
if(mode <3) //Sinyal stabilizasyonu için
{
buffer_ccd[inc] = analogRead0();
}
else
{
buffer_ccd[inc] += analogRead0(); // mode 3 : cumul des vues pour gagner jusqu'à 16 bits maximum de dynamique, soit 16 vues
} //Mod 3: Birikmiş views 16 dinamik bit veya 16 görüş maksimum kazanmak
GPIOPinWrite(GPIO_PORTB_BASE, CLK|ROG, ROGhCLOCKb);
tempo_mic(38);
}