MrXploder
Joined: 14 Mar 2013 Posts: 6
|
MSGEQ7 7 Band Spectrum Analyzer Library for PIC18F2550 (WIP) |
Posted: Wed Nov 05, 2014 9:11 pm |
|
|
*Work in Progress*
For connections look datasheet...
Currently you can only connect the AnalogOut from MSGEQ7 to pin A0 on the PIC, this is because A0 is the only pin that can be set to Analog without affecting the function of other pins (if you want to use A1, A0 must be analog too).. but for STROBE and RESET you can choose any pin..
MSGEQ7.h
Code: |
#define MSGEQ7_STROBE pin_
#define MSGEQ7_RESET pin_
volatile unsigned int8 MSGEQ7_Data[7];
void MSGEQ7_Init(){
setup_adc(ADC_CLOCK_DIV_64);
set_adc_channel(0);
setup_adc_ports(AN0);
delay_ms(100);
}
void MSGEQ7_Read(){
output_high(MSGEQ7_RESET);
delay_us(1);
output_low(MSGEQ7_RESET);
delay_us(100);
for (int8 x=0;x<7;x++){
output_low(MSGEQ7_STROBE);
delay_us(100);
MSGEQ7_Data[x] = read_adc();
output_high(MSGEQ7_STROBE);
}
}
|
Example of use
Code: |
#include <18f2550.h>
#device ADC=8
#fuses NOMCLR
#use delay(clock=48M, crystal=16M)
#use FAST_IO(ALL)
#use rs232(baud=9600, xmit=pin_b6)
#include <MSGEQ7.h>
void main(){
set_tris_a(0b0000001);
set_tris_b(0b00000000);
set_tris_c(0b00000000);
MSGEQ7_Init();
while(true){
MSGEQ7_Read();
for(int x=0;x<7;x++){
printf("Spectrum Data %d: %d", x+1,MSGEQ7_Data[x]);
}
delay_ms(1000);
}
}
|
|
|