CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

MSGEQ7 7 Band Spectrum Analyzer Library for PIC18F2550 (WIP)

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
MrXploder



Joined: 14 Mar 2013
Posts: 6

View user's profile Send private message

MSGEQ7 7 Band Spectrum Analyzer Library for PIC18F2550 (WIP)
PostPosted: Wed Nov 05, 2014 9:11 pm     Reply with quote

*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);
   }
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group