Beruflich Dokumente
Kultur Dokumente
h>
#use delay(clock = 40000000)
#fuses H4,PUT,NOWDT
#include <lmslib.h>
#include <lmslib.c>
#include <clcd.c>
// Globals......................................................................
...............\\
const int filter_length = 4;
int buf[filter_length] = {0}; // Store ADC Values ....................\\
int signal,noise,EOB,B OB,tptr,buf_count;
int out,i,outs;
// LMS vari ables...............................................................
.............\\
split_float fout, *fptr;
split w0,w1,w2,w3;
split n0,n1,n2,n3;
split es0,es1,es2,es3;
split up0,up1,up2,up3;
split s, eta, err, error, * ptr;
#INT_TIMER2
void t2_isr() {
T2CON = 0x06;
// Restart Timer
// Sample channel 0 for noise
ADCON0 = 0x81;
// Set ADC Channel 0
es0.real = 0; es0.frach = 0; es0.fracl = 0; es0.sign
es1.real = 0; es1.frach = 0; es1.fracl = 0; es1.sign
es2.real = 0; es2.frach = 0; es2.fracl = 0; es2.sign
es3.real = 0; es3.frach = 0; es3.fracl = 0; es3.sign
up0.real = 0; up0.frach = 0; up0.fracl = 0; up0.sign
up1.real = 0; up1.frach = 0; up1.fracl = 0; up1.sign
up2.real = 0; up2.frach = 0; up2.fracl = 0; up2.sign
up3.real = 0; up3.frach = 0; up3.fracl = 0; up3.sign
err.real = 0; err.frach = 0; err.fracl = 0; err.sign
=
=
=
=
=
=
=
=
=
0;
0;
0;
0;
0;
0;
0;
0;
0;
delay_us(6);
ADCON0 = 0x85;
// Start ADC Conversion
while(bit_test(ADCON0,2));
noise = ADRESH;
// Read ADC Value
ADCON0 = 0x89;
// Set ADC Channel 1
// Buffer Noise Values and convert to floats
buf_count = filter_length;
FSR1L = tptr;
FSR2L = &n0.sign;
#asm
// Add the latest ADC value to the buffer
movf EOB,0
// Move to W Register
cpfseq FSR1L
// Check if ptr is at EOB
bra neq
movff noise,INDF1
//ptr has reached EOB: insert value
movff BOB,FSR1L
//Reset pointer to begining of Buffer
bra
end
neq:
movff noise,POSTDEC1 //Put data in Buffer and advance ptr
end:
// Unload ADC Value from Buffer and poppulate n0..nN
unl:
movf
BOB,0
cpfseq FSR1L
bra
aneq
movff EOB,FSR1L
//
movff INDF1,out
bra
aend
aneq:
movff
PREINC1,out
aend:
// Move to W Register
// Check if ptr is at BOB
Pointer is at BOB.. Warp Pointer to EOB
// Extract Data
// Extract Data from Buffer
if (signal>=127) {
signal = signal-127;
s.frach = signal;
s.fracl = signal;
s.real = 0;
s.sign = 0;
}
else {
signal = 128-signal;
s.frach = signal;
s.fracl = signal;
s.real = 0;
s.sign = 1;
}
// Calculate estimate using...... //' esN = wN * nN;'
mul();
mul();
mul();
mul();
=
=
=
=
// Start ADC:
* n0..nN;'
mul();
mul();
mul();
mul();
add();
add();
add();
add();
ADCON1 = 0x02;
{
rs;
unused1;
unused2;
enable;
data : 4;
}
// Sends a whole byte to the LCD by making use of the Send nibble function
// The first parameter address decided whet her the byte is an instruction or dat
a
void lcd_send_byte( byte address, byte n ) {
delay_ms(3);
lcd.rs = 0;
delay_us(1);
lcd.rs = address;
delay_cycles(1);
lcd.enable = 0;
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
// Initializes the LCD display..
void lcd_init() {
byte i;
set_tris_c(0);
lcd.rs = 0;
lcd.enable = 0;
delay_ms(15);
for(i=1;i<=3;++i) {
lcd_send_nibble(3);
delay_ms(5);
}
lcd_send_nibble(2);
for(i=0;i<=3;++i)
lcd_send_byte(0,LCD_INIT_STRING[i]);
}
// Sets the cursor on the screen where the character is to be printed.
void lcd_gotoxy( byte x, byte y) {
byte address;
address=lcd_line_addresses[y]+x;
lcd_send_byte(0,0x80|address);
}
void lcd_putc( byte c) {
switch (c) {
case '\f' : lcd_send_byte(0,1);
delay_ms(2);
case '\b'
default
}
}
break;
: lcd_send_byte(0,0x10); break;
: lcd_send_byte(1,c);
break;