// copyright:
// Copyright (c) 2008 - thierry.poncery@premiss.org
//#define __18f458
#include <pic18fregs.h>
#include <pic18f458.h>
#include "DAC_controle.h"
#include "LCD.h"
#include "pic.h"
#include "adi1955.h"
#include "pcm1792.h"
#include "vol_levels.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#pragma stack 0x300 0xff
typedef unsigned int word;
typedef unsigned char byte;
// Word Config for PIC18F458
code char at __CONFIG1H CONFIG1H = _OSC_HS_1H & _OSCS_OFF_1H;
code char at __CONFIG2L CONFIG2L = _PUT_ON_2L & _BODEN_OFF_2L & _BODENV_2_0V_2L;
code char at __CONFIG2H CONFIG2H = _WDT_OFF_2H & _WDTPS_1_128_2H;
code char at __CONFIG4L CONFIG4L = _STVR_ON_4L & _LVP_ON_4L & _BACKBUG_OFF_4L;
code char at __CONFIG5L CONFIG5L = _CP_0_OFF_5L & _CP_1_OFF_5L & _CP_2_OFF_5L & _CP_3_OFF_5L;
code char at __CONFIG5H CONFIG5H = _CPB_OFF_5H & _CPD_OFF_5H;
code char at __CONFIG6L CONFIG6L = _WRT_0_OFF_6L & _WRT_1_OFF_6L & _WRT_2_OFF_6L & _WRT_3_OFF_6L;
code char at __CONFIG6H CONFIG6H = _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H;
code char at __CONFIG7L CONFIG7L = _EBTR_0_OFF_7L & _EBTR_1_OFF_7L & _EBTR_2_OFF_7L & _EBTR_3_OFF_7L;
code char at __CONFIG7H CONFIG7H = _EBTRB_OFF_7H;
// For printf function
/*
PUTCHAR( c )
{
TXEN1;
TXREG=c;
DelayUs(250); // 250us
}
*/
void PUTCHAR(char c)
{
TXEN1;
TXREG=c;
DelayUs(250); // 250us
}
// First text displayed on the LCD
byte * M_Titre=" << Premiss D2 >>";
// Function prototype
void DelayMs(unsigned char cnt);
void AD_write_SPI(unsigned int spi_data, unsigned int len);
void PCM_write_SPI(unsigned int spi_data, unsigned int len);
void ADI_Volume(unsigned int volume);
void PCM_Volume(unsigned int volume);
void ADI_VolumeChg(unsigned int volume,unsigned int sens);
// Strutures
typedef struct
{
unsigned char Name[10];
unsigned char Value[10];
} DACValue;
typedef struct
{
unsigned char ItemNumero;
unsigned char ItemName[11];
} Menu;
typedef struct
{
unsigned char ItemNumero; // Numero d'order dans le menu
unsigned char ItemName[10]; // Nom a afficher
unsigned char ItemCurValue[11]; // Valeur courante
unsigned char ItemDefValue[11]; // Valuer pas defaut ?
} AD_Config;
unsigned int mod_lev = 0;
unsigned int auto_incr = 1;
unsigned int flag,i;
void main()
{
// DAC AD Datas init
unsigned int PCMvol=255; // Volume register value to minimum at boot
unsigned int ADIvol= Volvalue[PCMvol]; // Volume register value to minimum at boot
long DACdB; // Attenuation level in dB pour les 2 DAC
// Gestion des fonctions DACs
unsigned int AD_MCi=0; // index des ModeClock pour AD1955
unsigned int DACno=0; // init DAC 0->AD1955 - 1->PCM1792 - 2-> Les 2 en meme temps !
unsigned char * Menu1[2]={"AD1955","PCM1792"};
unsigned char * L_Titre[3]={"<< Premiss ADI2 >>","<< Premiss PCM2 >>","<< Premiss Duo2 >>"};
unsigned int touche = 0;
unsigned int clavier = 0;
unsigned int Rt = 0;
// TbD if I keep them -> LCD Display Buffer
unsigned char CmdL1[21]=" ";
unsigned char CmdL2[21]=" ";
// Used to clear one line
unsigned char ClsLine[21]=" ";
// Gestion du bouton de Volume ( Formule du sens : sens=(Vup==Vdw_old) )
unsigned int VolSens = 0; // 0 ou 1 sens en cours du capteur
unsigned int Vup=0,Vup_old=0;
unsigned int Vdw=0,Vdw_old=0;
// Menu CommonItem Select
unsigned char * CommonSelect[2]={"Volume :","Src input:"};
// Menu AD1955
// Values are managed in text format to be stored in Eeprom
unsigned char * AD_ItemSelect[6]={"PCM Rate :","Serial Wd:","MCLK Mode:","DEM Curve:","Muting :","Vol def :"};
// REG00 - bit [15]
DACValue AD_Power[2]={{"Operation","0"},{"PowerDown","1"}};
// REG00 - bit [14]
DACValue AD_Mute[2]={{"OFF","0"},{"ON","1"}};
// REG00 - bit [13:12]
DACValue AD_DataFormat[4]={{"PCM","0"},{"Ext. DF","1"},{"SACD Slv","2"},{"SACD Mast","2"}};
// REG00 - bit [11:10]
DACValue AD_OutputFormat[3]={{"Stereo","0"},{"Mono Left","2"},{"Mono right","3"}};
// REG00 - bit [9:8]
DACValue AD_PcmSampleRate[3]={{"48kHz","0"},{"96kHz","1"},{"192kHz","2"}};
// REG00 - bit [7:6]
DACValue AD_DeEmphasisCurveSelect[4]={{"None","0"},{"32.0kHz","2"},{"44.1kHz","1"},{"48.0kHz","3"}};
// REG00 - bit [5:4]
DACValue AD_SerialDataFormat[4]={{"I2S","0"},{"Rig Just","1"},{"DSP","2"},{"Left J","3"}};
// REG00 - bit [3:2]
DACValue AD_SerialDataWidth[4]={{"24b","0"},{"20b","1"},{"18b","2"},{"16b","3"}};
// REG01 - bit [10:9]
DACValue AD_ClockMode[3]={{"256Fs","0"},{"512Fs","1"},{"768Fs","2"}};
// REG02 - bit [15:2]
DACValue AD_LeftVolume[1]={{"","0"}};
// REG03 - bit [15:2]
DACValue AD_RightVolume[1]={{"","0"}};
// Menu PCM1792
unsigned char * PCM_ItemSelect[5]={"PCM rate :","PCM long :","DEM Curve:","MCLK Mode:","Muting :"};
unsigned char * PCM_MclockMode[3]={"256Fs","512Fs","768Fs"};
// Tableau clok Mode Version 1
unsigned char * AD_MclockMode[3]={"256Fs","512Fs","768Fs"};
Menu AD_UserL1[4]={ {0,""},{1,"Volume :"},{2,"Src input:"},{9,""} };
// PCM rate : xxxkHz * PCM long : xxbit * MCLK Mode : xxxFs * DEM curve : xxxkHz * Muting : xxx * Vol def : -xxxdB * Src input :ABCDEFGH
Menu AD_SetupL1[5]={ {0,""},{1,"PCM rate :"},{2,"ModeClock:"},{3,"SampRate :"},{9,""} };
//AD_Config AD_SetupL1[5]={ {0,"",,},{1,"PCM rate : xxxkHz",,},{2,"ModeClock:",,},{3,"SampRate :",,},{9,"",,} };
stdout = STREAM_USART; // For printf, fprintf, ...
KBD_Rpt(0); // Reapeat ON
pic_io_init();
pic_init_usart();
LCD_Cls(); // clear LCD
LCD_Pos(1,1); // cursor Line, colonne
LCD_Print(M_Titre); // Hello !!
power_start(); // wait power supply stabilisation
ADI_com_init(); // init SPI Levels for ADI1955
PCM_com_init(); // init SPI Levels for PCM1792
PCM_ModeMono();
ADI_ModeMono();
ADI_Volume(0); // volume at minimum, before starting
PCM_Volume(0); // volume at minimum, before starting
DACdB = (255-PCMvol)*0.5; // Maxi a -120dB -> Rajouter le (-) en texte.
flag = 0; // 0=48 - 1=96 - 2=192
LCD_Pos(2,1);
printf("%s ModClk %s\n",Menu1[DACno],AD_MclockMode[AD_MCi]);
// Main loop, to be changed with a timer loop !!
while(1)
{
// Volume controle
Vup=KVup;
Vdw=KVdw;
if ( KVup!=Vup_old || KVdw!=Vdw_old ) // Si ca a bouge ...
{
VolSens=(Vup==Vdw_old);
if ( VolSens == 1 ) // Volume Up
{
if (ADIvol < AD_MAX_VOL)
{
if (ADIvol < (AD_MAX_VOL - INC_VOL))
{
ADIvol += INC_VOL;
LCD_Pos(2,1);
printf("%s Vol %d \n",Menu1[DACno],ADIvol);
}
else
{
ADIvol = AD_MAX_VOL;
LCD_Pos(2,1);
printf("%s Vol Max \n",Menu1[DACno]);
}
}
mod_lev = 1;
auto_incr = 0;
}
else // volSens=0 -> volume Down
{
if (ADIvol > 0)
{
if (ADIvol > INC_VOL)
{
ADIvol -= INC_VOL;
LCD_Pos(2,1);
printf("%s Vol %d \n",Menu1[DACno],ADIvol);
}
else
{
ADIvol = 0;
LCD_Pos(2,1);
printf("%s Vol Min \n",Menu1[DACno]);
}
}
mod_lev = 1;
auto_incr = 0;
}
}
Vup_old=Vup; // Memoire
Vdw_old=Vdw; // ...
// Gestion liaison serie
Rt = PIR1&32; // Lecture bit RCIF ( bit 5 ) si 1 si reception complete
if ( Rt == 32 ) // Si reception d'un octet ...
{
touche = 0; // Une touche a ete appuye
clavier=RCREG; // lecture reg reception
if ( clavier == 'M' )
{
DACno=0; // AD1955
LCD_Pos(1,1); // cursor Line, colonne
printf("%s\n",L_Titre[DACno]);
LCD_Pos(2,1);
LCD_Lclear();
LCD_Pos(2,1);
printf("%s ModClk %s\n",Menu1[DACno],AD_MclockMode[AD_MCi]);
}
else if ( clavier == 'N' )
{
DACno=1; // PCM1792
LCD_Pos(1,1); // cursor Line, colonne
printf("%s\n",L_Titre[1]);
LCD_Pos(2,1);
Pic4box1.tar.gz_des
版权申诉
188 浏览量
2022-09-22
19:59:29
上传
评论
收藏 9KB GZ 举报
林当时
- 粉丝: 103
- 资源: 1万+
最新资源
- labelImg安装指导书.docx
- 2023AI自有光-她经济消费新图鉴(2023)-百度营销.pdf
- 2022中国新能源汽车内容生态趋势洞察(1).pdf
- Docker技术:Docker安装与配置教程+运维技术+超融合+虚拟技术+云计算
- ZeRO Memory Optimizations Toward Training LLM.pdf
- 高效SQL语句编写(how-to-write-efficient-sql)
- ZeroTermux-release_sign.apk
- 非弹性斜碰撞物理课件模拟-HTML网页制作
- 软件测试学习日志-测试基础-day02
- 制作一个简单的进销存(库存管理)页面.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈