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

La Programmation C Du Processeur Embarqué ARM7TDMI-S™ Et Des Différents Périphériques

This document describes several manipulations for programming an ARM7TDMI microcontroller and its peripherals. It includes examples of initializing ports and pins, using interrupts, and sending characters to an LCD screen via I2C. The final manipulation uses an I2C temperature sensor to measure and display the minimum, maximum, and average temperature readings over time on an LCD screen.

Uploaded by

Driss Aabour
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 views6 pages

La Programmation C Du Processeur Embarqué ARM7TDMI-S™ Et Des Différents Périphériques

This document describes several manipulations for programming an ARM7TDMI microcontroller and its peripherals. It includes examples of initializing ports and pins, using interrupts, and sending characters to an LCD screen via I2C. The final manipulation uses an I2C temperature sensor to measure and display the minimum, maximum, and average temperature readings over time on an LCD screen.

Uploaded by

Driss Aabour
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/ 6

TP4 : La programmation C du processeur embarqué

ARM7TDMI-S™ et des différents périphériques

Manipulation 1 :
Premiers pas dans la programmation du microcontrôleur ARM

#Include <lpc2124.h>
Void init_mc(void) ;
Void wait(unsigned int ) ;

Int main (void)


{
Init_mc();
While(1)
{
GPIO0_IOCLR |= (1 <<8);
Wait(0x001FFFF);
GPIO0_IOSET |= (1<<8);
Wait(0x001FFFFF);
}
Return 0 ;
}

Void init_mc(){
GPIO0_IODIR |= (1<<8);
}
Void wait ( unsigned int a )
{
While(a)
{ a--;}
}
Manipulation 2 : Ports et broches de ports
#Include <lpc2124.h>
Void init( void) ;
Void wait(unsigned int ) ;

Int main (void)


{
Unsigned int in ;
Unsigned char bitmask=0x01;
Init();
While(1)
{
In = GPIO1_IOPIN & (1<<16);
Switch (in) {
Case(0<<16):
Bitmask <<=1;
If (bitmask == 0)
Bitmask =1;
Wait (0x001FFFFF);
Break;
Case(1<<16):
Bitmask >>=1;
If (bitmask == 0)
Bitmask =(1<<7);
Wait (0x001FFFFF);
Break;
}

GPIO0_IOSET |= 0xFFFFFFFF
GPIO0_I0CLR |=(bitmask <<8);
}
Return 0 ;
}

Void init (){


GPIO0_IODIR |= ((1<<8)| (1<<9)| (1<<10)| (1<<11)| (1<<12)| (1<<13)|
(1<<14)| (1<<15)) ;
GPIO0_IOCLR |= (1<<8); // car 0 : allumée et 1 : etteinte
}
Void wait ( unsigned int a )
{
While(a)
{ a--;}
}
Manipulation 3 : Interruption externe

#include <lpc2124.h>
Void init_mc(void);
Void init_ext_int3(void);
Void extint3(void)__attribute__((interrupt(“IRQ”)));
Void wait(unsigned int) ;
Int main(void)
{
Init_mc() ;
Init_ext_int3() ;
While(1){
} Return 0 ; }
Void init_mc(void)
{
GPIO1_IODIR |= ((1<<16)| (1<<17)| (1<<18)| (1<<19));
}
Void init_ext_int3(void)
{
PCB_PINSEL0 |= ((1<<19)|(1<<18)) ;
SCB_EXTMODE |=(1<<3) ;
SCB_EXTPOLAR |=(1<<3) ;
VICIntSelect &=~ (1<<17) ;
VICVectAddr0 =(unsigned long) extint3 ;
VICIntEnable |=(1<<17);
VICVectCntl0 = (1<<5) | 17; }
Void extint3(void)
{
Unsigned int in ;
In = GPIO0_IOPIN;
In &= (1<<23) | (1<<22) |(1<<21) |(1<<20) ;
GPIO1_IOSET =(1<<19) | (1<<18) |(1<<17)|(1<<16);
Switch (in) {
Case((1<<23) | (1<<22) | (1<<21) | (0<<20)):
GPIO1_IOCLR |= (1<<16);
Break
Case((1<<23) | (1<<22) | (0<<21) | (1<<20)):
GPIO1_IOCLR |= (1<<17);
Break;
Case((1<<23) | (0<<22) | (1<<21) | (1<<20)):
GPIO1_IOCLR |= (1<<18);
Break;
Case((0<<23) | (1<<22) | (1<<21) | (1<<20)):
GPIO1_IOCLR |= (1<<19);
Break;
} }
Void wait ( unsigned int a )
{
While(a)
{ a--;}
}
Manipulation 5 : Sortie de caractères sur l'écran LCD I²C

#include <lpc2124.h>
#include “iic.h”
#include “lcd.h”

Void iic.init(void);
Void Lcd.init(void);

Int main(void)
{
I2c.init();
Lcd.init();

LCD_gotoXY(2,5);
I2C_SendSlaveAdress(adr_lcd);
I2C_WriteData(0x40);

While(1)
{
wait(30000);
I2C_WriteData('H'|0x80); // send H
I2C_WriteData('e'|0x80); // send e
I2C_WriteData('l'|0x80); // send l
I2C_WriteData('l'|0x80); // send l
I2C_WriteData('o'|0x80); // send o
I2C_STOP();
Return 0 ;
}
}
Manipulation 6 : Utilisation du capteur de température I²C LM75

#include <lpc2124.h>
#include “iic.h”
#include “lcd.h”
#include “LM75.h”

Void mc_init() ;
Void i2c_init(void);
Void lcd_init(void);
Void lm75_init(void);
Void wait(unsigned char );
Void CapterT();
Void boutons();
Void showmin();
Void showmax();
Void showmoy();
UNSIGNED CHAR min =90 , max =0 , moy = 0;
UNSIGNED CHAR tempe[100];
UNSIGNED int in ;

Int main (void)


{
Mc_init() ;
Iic_init();
Lcd_init();
Lm75_init();
While(1)
{ CapterT();
Boutons(); }
Return 0 ;
}

Void CapterT()
{ int i=0;
For( i=0;i<100;i++)
{
Tempe[i] = TEMP_IN() ;
If ( Tempe[i] < min ) min = Tempe[i];
If ( Tempe[i] > max ) max= Tempe[i];
Moy+= Tempe[i];
Wait(0xFFFF); }}
Void Boutons()
{
In = GPIO0_IOPIN;
In &= (1<<8) | (1<<9);
SWITCH (in)
{
Case((1<<8)| (0<<9) :
Showmin();
Break;
Case((0<<8)| (1<<9) :
Showmax();
Break;
Default : showmoy(); break; } }

Void Showmin()
{
TEMP_BCD(min);
LCD_GOTOXY(2,5);
LCD_SEND_NUMBER(temperature100);
LCD_SEND_NUMBER(temperature100);
LCD_SEND_NUMBER(temperature100);
LCD_SENDGND();
Wait( 0xFFFF);
}
Void Showmax()
{
TEMP_BCD(max);
LCD_GOTOXY(2,5);
LCD_SEND_NUMBER(temperature100);
LCD_SEND_NUMBER(temperature100);
LCD_SEND_NUMBER(temperature100);
LCD_SENDGND();
Wait( 0xFFFF);
}
Void Showmoy()
{
TEMP_BCD(moy/100);
LCD_GOTOXY(2,5);
LCD_SEND_NUMBER(temperature100);
LCD_SEND_NUMBER(temperature100);
LCD_SEND_NUMBER(temperature100);
LCD_SENDGND();
Wait( 0xFFFF);
}
Void mc_init()
{ GPIO0_IODIR |= (0<<9)|(0<<8); }

Void wait(unsigned char val)


{ While( val ) Val--; }

You might also like