Minggu, 25 Maret 2012

Pemprograman TPA81 degan CVAVR




 Gabar 1. Konvigurasi PIN TPA81 dengan ATMega 8535
/************************
kode pemprograman di CVAVR
**************************/
#include <mega8535.h>
#include <delay.h>
#include <stdio.h>
// I2C Bus functions
#asm
.equ __i2c_port=0x1B ;PORTA
.equ __sda_bit=1
.equ __scl_bit=0
#endasm
#include <i2c.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x12 ;PORTD
#endasm
#include <lcd.h>
unsigned char Msg1[16];
unsigned char Msg2[16];
// Declare your global variables here
int data,i;
unsigned char reg,revision,ambient,pixel[8];
void TPA_read()
{
delay_ms(40); //wait for 40mS to get accurate reading
i2c_start();
i2c_write(0xD1);
i2c_write(reg);
i2c_start();
i2c_write(0xD1);
data=i2c_read(0);
i2c_stop();
}
void main(void)
{
.
.
.
// I2C Bus initialization
i2c_init();
// LCD module initialization
lcd_init(16);
while (1)
{
// Place your code here
reg=0x00;
TPA_read();
revision=data;
reg=0x01;
TPA_read();
ambient=data;
for (i=0;i<8;i++) {
reg=reg+1; // reg=0x02,0x03,...,0x09
TPA_read();
pixel[i]=data;
}
sprintf(Msg1,"%3d %3d %3d %3d",pixel[0],pixel[1],pixel[2],pixel[3]);
sprintf(Msg2,"%3d %3d %3d %3d",pixel[4],pixel[5],pixel[6],pixel[7]);
lcd_gotoxy(0,0);lcd_puts(Msg1);
lcd_gotoxy(0,1);lcd_puts(Msg2);
};
}

Tidak ada komentar:

Posting Komentar

Secerca Harapan Didepan Mata