芯片KC89C72 可编程声音发生器(PSG)
一片从游戏器上拆下来的KC89C72。MCU使用的51。
/* \file main.c - Keil C v8.02* Project id: 00595cf9-8de6-4a57-b940-eb0347ac9e13** \details This file is part of the KC89C72 project.** History:* Date Auther Description* -------------------------------------------------------------* 2013-01-06 Perry Initial created.** Note:* This source code can be used, modified, and redistributed under the* terms of the license agreement that is included in the lcd_h018in01 package* By continuing to use, modify, or redistributed this code you indicate* that you have read the license and understand and accept it fully.*/#include "main.h"#define PSG_KC89C72_REG_R0 0x00 // 通道A频率设置,低8位。
#define PSG_KC89C72_REG_R1 0x01 // 通道A频率设置,高4位。
#define PSG_KC89C72_REG_R2 0x02 // 通道B频率设置,低8位。
#define PSG_KC89C72_REG_R3 0x03 // 通道B频率设置,高4位。
#define PSG_KC89C72_REG_R4 0x04 // 通道C频率设置,低8位。
#define PSG_KC89C72_REG_R5 0x05 // 通道C频率设置,高4位。
#define PSG_KC89C72_REG_R6 0x06 // 噪音频率设置,5位。
#define PSG_KC89C72_REG_R7 0x07 // I/O端口与混音设置。
#define PSG_KC89C72_REG_R8 0x08 // 通道A电平设置。
#define PSG_KC89C72_REG_R9 0x09 // 通道B电平设置。
#define PSG_KC89C72_REG_RA 0x0A // 通道B电平设置。
#define PSG_KC89C72_REG_RB 0x0B // 包络频率。微调,8位。
#define PSG_KC89C72_REG_RC 0x0C // 包络频率。粗调,8位。
#define PSG_KC89C72_REG_RD 0x0D // 包络形状。低4位(CONT/ATT/ALT/HOLD)。
#define PSG_KC89C72_REG_RE 0x0E // 扩展/外设端口A数据寄存器,8位。
#define PSG_KC89C72_REG_RF 0x0F // 扩展/外设设口B数据寄存器,8位。#define chip_addr PSG_KC89C72_DA
#define chip_data PSG_KC89C72_DAsbit key = P1^0;sbit bc1 = PSG_KC89C72_BC1;
sbit bc2 = PSG_KC89C72_BC2;
sbit bdir = PSG_KC89C72_BDIR;
sbit sel = PSG_KC89C72_SEL;
sbit a8 = PSG_KC89C72_A8;
sbit a9 = PSG_KC89C72_A9;
sbit reset = PSG_KC89C72_RESET;
sbit clk = PSG_KC89C72_CLK;#define set_addr_mode() \bc1 = 1; \bc2 = 1; \bdir = 1; \a8 = 1; \a9 = 0#define set_read_mode() \bc1 = 1; \bc2 = 1; \bdir = 0; \a8 = 0#define set_write_mode() \bc1 = 0; \bc2 = 1; \bdir = 1; \a8 = 0#define set_inactive_mode() \bc1 = 0; \bc2 = 1; \bdir = 0; \a8 = 0void chip_write(uint8 reg, uint8 val)
{set_addr_mode();delay_xms(1);chip_addr = reg & 0xf;delay_xms(1);set_write_mode();delay_xms(1);chip_data = val;delay_xms(1);set_inactive_mode();delay_xms(1);chip_data = 0xff;
}void chip_reset()
{reset = 0;delay_xms(1);reset = 1;
}void chip_init()
{chip_reset();sel = 1;chip_write(PSG_KC89C72_REG_R0, 150);chip_write(PSG_KC89C72_REG_R1, 10);chip_write(PSG_KC89C72_REG_R2, 0xff);chip_write(PSG_KC89C72_REG_R3, 0xf);chip_write(PSG_KC89C72_REG_R4, 8);chip_write(PSG_KC89C72_REG_R5, 0);chip_write(PSG_KC89C72_REG_R6, 1);chip_write(PSG_KC89C72_REG_R7, 0xf8);chip_write(PSG_KC89C72_REG_R8, 0x2);chip_write(PSG_KC89C72_REG_R9, 0xf);chip_write(PSG_KC89C72_REG_RA, 0x1f);chip_write(PSG_KC89C72_REG_RB, 0x28);chip_write(PSG_KC89C72_REG_RC, 0x0);chip_write(PSG_KC89C72_REG_RD, 0xe);
}void main()
{uint8 vol = 0xf;chip_init();while (1){if (!key){delay_xms(500);if (vol = 0)vol = 0xf;vol--;chip_write(PSG_KC89C72_REG_R1, vol & 0xf);chip_write(PSG_KC89C72_REG_R3, vol & 0xf);chip_write(PSG_KC89C72_REG_R5, vol & 0xf);}}
}// 延时子程序毫秒单位。
void delay_xms(uint16 ms)
{while (ms--)delay_xus(109);
}// 延时子程序微秒单位。
void delay_xus(uint16 us)
{while (us--);
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
