The PSoC Microcontroller with FM Radio Receiver Module RDA5807SS.
PSoC กับ FM Radio Receiver Module (RDA5807SS)
อุปกรณ์
PSoC CY8C27443
FM Radio Receiver Module RDA5807SS
LCD
เครื่องมือ
PSoC Designer 5.2
ความสามารถ
PSoC ทำหน้าที่เป็น ตัวควบคุม ให้ภาครับ FM ทำงาน
แสดงค่าความดังและสถานีได้ทาง LCD
วงจร
PSoC Config
1. Global
CPU clk 3 MHz
2. Pinout
Port_0_0 - Port_0_5 Pull down
3. LCD
module LCD
LCD Port Port_2
BarGraph Enable
4. I2C
module I2CHW
Read_Buffer_type Ram Only
CPU_Clk_speed 6MHz OR LESS
I2C Clock 100K standard
I2C Pin P[1]5 - P[1]7
ทดลอง 1 กำหนดให้ GPIO1 GPIO2 GPIO3 เป็น 1 ที่ละบิต และสุดท้ายเป็น 1 พร้อมกัน
โปรแกรม main.c
//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------
#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
#include <stdlib.h>
#include "delay.h"
#include "ioport.h"
#define SLAVE_ADDRESS 0x10
/* setup a 12 byte buffer */
BYTE rxBuffer[12];
BYTE status;
char TextBuff[6];
#include "fm_module.h"
void main(void)
{
BYTE i,j;
Delay1mS(100);
LCD_1_Start(); // Initialize LCD
LCD_1_Position(0,0);
LCD_1_PrCString("FM Tuner");
I2CHW_1_Start(); // Start the master //
I2CHW_1_EnableMstr();
M8C_EnableGInt; // Enable the global and local interrupts //
I2CHW_1_EnableInt();
Soft_Reset();
wr_config();
Delay1mS(300);
config[5] = 0x03; //GPIO1 = 1
wr_config();
Delay1mS(300);
config[5] = 0x0c; //GPIO2 = 1
wr_config();
Delay1mS(300);
config[5] = 0x30; //GPIO3 = 1
wr_config();
Delay1mS(300);
config[5] = 0x3f; //all GPIO = 1
wr_config();
Power_Up();
while(1)
{
}
}
------------------------------------------------------------------------------------------------------------------------
โปรแกรม fm_module.h
void setbit( BYTE *ptr1, BYTE i);
void clrbit( BYTE *ptr1, BYTE i);
void rd_status(void);
void wr_config(void);
void Soft_Reset(void);
void Power_Up(void);
void Seek_Up(void);
void Seek_Down(void);
void Vol_Up(void);
void Vol_Down(void);
void Freq_Up(void);
void Freq_Down(void);
unsigned char config[10] = {0xD0,0x01, 0x11,0x82, 0x04,0x00, 0x86,0xdf, 0x40,0x00}; //1101 0000
// 0 1 2 3 4 5 6 7 8 9
// Register '-----02-----' '-----03-----' '-----04-----' '-----05-----' '---06---'
// Bit 15 14 ...0 15 14 ..0 15 14 ..0 15 14 ..0 15 14 ..0
unsigned char txt[6];
//unsigned char keypadPort at PORTB;
unsigned char indicator[4];
//bit flag_,BASS_Flag,MONO_Flag,MUTE_Flag;
unsigned char flag_,BASS_Flag,MONO_Flag,MUTE_Flag;
unsigned char rssi,i,kp,freq1,freq2;
unsigned int channel,vol;
// Set bit i of the memory at address ptr1.
// setbit(&txBuffer[1] , i);
void setbit( BYTE *ptr1, BYTE i)
{
BYTE j = 1;
if(i<8)
{
while(i>0)
{
j<<=1;
--i;
}
*ptr1|= j | *ptr1;
}
}
// Clear bit i of the memory at address ptr1.
// clrbit(&txBuffer[1] , i);
void clrbit( BYTE *ptr1, BYTE i)
{
BYTE j = 1;
if(i<8)
{
while(i>0)
{
j<<=1;
--i;
}
j = j^0xff;
*ptr1 = j & *ptr1;
}
}
void wr_config(void)
{
// Send the contents of the data in Config buffer
I2CHW_1_bWriteBytes(SLAVE_ADDRESS, config, 10, I2CHW_1_CompleteXfer);
while(!(I2CHW_1_bReadI2CStatus() & I2CHW_WR_COMPLETE)); // Wait until the data is transferred
I2CHW_1_ClrWrStatus(); // Clear Write Complete Status bit
}
void Soft_Reset(void)
{
setbit(&config[1],1);
wr_config();
clrbit(&config[1],1);
}
void Power_Up(void)
{
setbit(&config[3],4);
setbit(&config[1],0);
wr_config();
clrbit(&config[3],4);
flag_=1;
}