Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // **************************************************************************
- //
- // Demo program for labs
- //
- // Subject: Computer Architectures and Parallel systems
- // Author: Petr Olivka, petr.olivka@vsb.cz, 08/2016
- // Organization: Department of Computer Science, FEECS,
- // VSB-Technical University of Ostrava, CZ
- //
- // File: Main programm for I2C bus
- //
- // **************************************************************************
- //projde vsechny stanice fekvence a pro kazdou vypise kvalitu signalu a zobrazi ho na ledkach 88 / 108
- #include <mbed.h>
- #include "i2c-lib.h"
- #include "si4735-lib.h"
- //************************************************************************
- // Direction of I2C communication
- #define R 0b00000001
- #define W 0b00000000
- Serial pc( USBTX, USBRX );
- #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
- double minfreq = 8800;
- double maxfreq = 10900;
- uint8_t ack = 0;
- void ladit(int freq){
- I2C_Start();
- ack |= I2C_Output( SI4735_address | W );
- ack |= I2C_Output( 0x20 ); // FM_TUNE_FREQ
- ack |= I2C_Output( 0x00 ); // ARG1
- ack |= I2C_Output( freq >> 8 ); // ARG2 - FreqHi
- ack |= I2C_Output( freq & 0xff ); // ARG3 - FreqLo
- ack |= I2C_Output( 0x00 ); // ARG4
- I2C_Stop();
- wait_ms( 100 );
- printf( "Frekvence: %d.%dMHz\r\n", freq / 100, freq % 100 );
- }
- uint8_t getqual(){
- uint8_t S1, S2, isStation, STBL, RSSI, SNR, MULT, FREQ;
- uint8_t ack = 0;
- I2C_Start();
- ack |= I2C_Output( SI4735_address | W );
- ack |= I2C_Output( 0x23 );
- ack |= I2C_Output( 0x00 );
- I2C_Start();
- ack |= I2C_Output( SI4735_address | R );
- S1 = I2C_Input();
- I2C_Ack();
- S2 = I2C_Input();
- I2C_Ack();
- isStation = I2C_Input() & 1;
- I2C_Ack();
- STBL = I2C_Input();
- I2C_Ack();
- RSSI = I2C_Input();
- I2C_Ack();
- SNR = I2C_Input();
- I2C_Ack();
- MULT = I2C_Input();
- I2C_Ack();
- FREQ = I2C_Input();
- I2C_NAck();
- I2C_Stop();
- return SNR;
- }
- void ledky(int snr){
- I2C_Start();
- ack = I2C_Output( 0b01000000 | 0b00001110 | W );
- if ( ack != 0 )
- pc.printf("chyba\n");
- if (snr == 0){
- I2C_Output( 0b000000000);
- }
- if (snr==1||snr==2){
- I2C_Output( 0b000000001);
- }
- if (snr==3||snr==4){
- I2C_Output( 0b000000011);
- }
- if (snr==5||snr==6){
- I2C_Output( 0b000000111);
- }
- if (snr==7||snr==8){
- I2C_Output( 0b000001111);
- }
- if (snr==9||snr==10){
- I2C_Output( 0b000011111);
- }
- if (snr==11||snr==12){
- I2C_Output( 0b00011111);
- }
- if (snr==13||snr==14){
- I2C_Output( 0b011111111);
- }
- if (snr>14){
- I2C_Output( 0b111111111);
- }
- I2C_Stop();
- }
- int main( void )
- {
- I2C_Init();
- pc.baud( 115200 );
- pc.printf( "K64F-KIT ready...\r\n" );
- I2C_Start();
- I2C_Stop();
- if ( ( ack = SI4735_Init() ) != 0 )
- {
- pc.printf( "Initialization of SI4735 finish with error (%d)\r\n", ack );
- return 0;
- }
- else
- pc.printf( "SI4735 initialized.\r\n" );
- pc.printf( "\nTunig of radio station...\r\n" );
- for(double d=minfreq;d<maxfreq;d++){
- ladit(d);
- int snr = getqual();
- printf("SNR: %i ",snr);
- ledky(snr);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement