📄 tz.tmp
字号:
/* uPSD3200.h - Register and bit definitons for the uPSD3200 family.
Created with Keil Software Inc uVision2 IDE. PK51 version 7.00.
- 7/08/02
>> New release.
*/
/* map3200.h
- 7/8/02
>> New release.
Created with Keil Software Inc uVision2 IDE. PK51 version 7.00.
Note: Please edit the addresses shown to match your system memory map and
edit any values neccesary to meet your platform specific hardware
*/
#ifndef _UPSD_HARDWARE_H_
#define _UPSD_HARDWARE_H_
#define FREQ_OSC 12000 // uPSD MCU Oscialtor Freq.
#define PSD_REG_ADDR 0x0200 // uPSD PSD Register I/O base addr
#define LCD_BASE_ADDR 0x0300 // LCD base address
//PWM IP
#define PWM_CH_no 4 // Total 8bit PWM channels
#define PWM_freq8 6000 // KHZ, 8bit PWM frequency
#define PWM_freq16 3000 // KHZ,16bit PWM frequency
#define DELAY_WAIT 5000 // Value for delay time
//ADC IP
#define ADC_CH_no 4 /* Total ADC channels */
#define ADC_clk_in 6000 /* KHZ,ADC clock input */
//TIMER IP
#define TIMER0_COUNT 0xdB62 // 10000h - ((16 Mhz / (12 * FREQ_OSC)) - 17)
//16Mhz = 0xcbfc 100hz
//12mHZ = 0xd8ff
//11.059Mhz = 0xdb62
//6Mhz = 0xec89
*/
/*#include "uPSD3200.h"*/ /* uncomment this include statement
to use the header files generated by
PSDsoft */
/* Function prototypes
*/
void uPSD_ADC_Init(unsigned char channel);
unsigned char uPSD_ADC_Read( unsigned char channel );
unsigned char uPSD_ADC_Prescaler( void );
void timer0_initialize (void);
unsigned timer0_count (void);
void timer0_delay (unsigned count);
void delay_10ms(void);
void delay_1sec(void);
void delay_2sec(void);
void delay_10sec(void);
void delay_0_5sec(void);
void delay_0_1sec(void);
void uPSD_PWM_Channel_8bit(unsigned char PWMCON_value, unsigned char PWM_channel_no, unsigned char Duty_Cyl);
void uPSD_PWM_Init_8bit(unsigned char PWM_channel_no, unsigned char Duty_Cyl);
void uPSD_PWM_Disable(void);
/*
Group: uPSD ADC Channels
Coverage: Prescale, Initialize, Read
*/
/*
Module: uPSD_ADC_Prescaler
Calculates prescaler register value for ADC ADSL register.
*/
#ifdef _U_A_P
unsigned char uPSD_ADC_Prescaler( void )
{
unsigned char ASCL_value;
ASCL_value = (unsigned char) ((FREQ_OSC/2)/ ADC_clk_in )-1;
return( ASCL_value);
}
#endif
/*
Module: uPSD_ADC_Init
Setup I/O ports and ADC prescaler value.
*/
#ifdef _U_A_I
void uPSD_ADC_Init (unsigned char channel)
{
switch (channel)
{
case 0:
{
P1SFS |= 0x10; /* Input port P1[4] = ADC_in[0] */
break;
}
case 1:
{
P1SFS |= 0x20; /* Input port P1[5] = ADC_in[1] */
break;
}
case 2:
{
P1SFS |= 0x40; /* Input port P1[6] = ADC_in[2] */
break;
}
case 3:
{
P1SFS |= 0x80; /* Input port P1[7] = ADC_in[3] */
break;
}
default:
break;
}
ASCL = uPSD_ADC_Prescaler(); /* Setup prescaler for ADC clock */
}
#endif
/*
Module: uPSD_ADC_Read
Reads analog signal from and returns converted value in ADAT SFR register.
*/
#ifdef _U_A_R
unsigned char uPSD_ADC_Read( unsigned char channel )
{
unsigned char channel_no;
uPSD_ADC_Init(channel); // Initialize ADC IP
ACON &= 0xD1; //Clears the input channels ~(00101110B) = (11010001B)
channel_no = channel << 2;
ACON |= channel_no; //Loads Channel to sampled
ACON |= 0x22; //Enables and Starts Conversion (0010xx1xB)
_nop_ ();
_nop_ (); //delay 2 instruction cycles: ADST: 1->0
while( (ACON & 0x01) != 1 ); //Waits for Conversion to end
ACON &= 0xDF; //disable ADC
return( (unsigned char) ADAT);
}
#endif
/*
Group: uPSD Timers
Coverage: Initialize, Generate Delays
*/
/*
Module: timer0_isr
Interrupt service routine for TIMER 0.
*/
#ifdef _T0_I
static unsigned timer0_tick;
static void timer0_isr (void) interrupt 1 using 1
{
/* This functon should never be called by a C or
assembly function. It will be executed automatically
when TIMER 0 overflows. */
/*------------------------------------------------
Stop timer, adjust the timer 0 counter so that we get another
interrupt in 10ms, and restart the timer.
------------------------------------------------*/
TR0 = 0; // stop timer 0
TL0 = TL0 + (TIMER0_COUNT & 0x00FF);
TH0 = TH0 + (TIMER0_COUNT >> 8);
TR0 = 1; // start timer 0
/*------------------------------------------------
Increment the timer tick. This interrupt should
occur approximately every 10ms. So, the resulotion
of the timer will be 100Hz not including interrupt
latency.
------------------------------------------------*/
timer0_tick++;
}
#endif
/*
Module: timer0_initialize
Enables TIMER 0 to interrupt at 100Hz.
*/
#ifdef _T0_IZ
void timer0_initialize (void)
{
EA = 0; // disable interrupts
timer0_tick = 0;
TR0 = 0; //stop timer 0
TMOD &= ~0x0F; //clear timer 0 mode bits
TMOD |= 0x01; // put timer 0 into 16-bit no prescale
TL0 = (TIMER0_COUNT & 0x00FF);
TH0 = (TIMER0_COUNT >> 8);
PT0 = 0; // set low priority for timer 0
ET0 = 1; //enable timer 0 interrupt
TR0 = 1; // start timer 0
EA = 1; // enable interrupts
}
#endif
/*
Module: timer0_count
Returns the current tick count of timer0.
*/
#ifdef _T0_C
unsigned timer0_count (void)
{
unsigned t;
EA = 0;
t = timer0_tick; //Encapsulate timer0_tick to ensure
// program does not access at same time
// as interrupt is updating it
EA = 1;
return(t);
}
#endif
/*
Module: timer0_delay
Waits for specified number of timer ticks to pass.
*/
#ifdef _T0_D
void timer0_delay (unsigned count)
{
unsigned start_count;
start_count = timer0_count (); // get the start count
while ((timer0_count () - start_count) <= count) // wait for count "ticks"
{
}
}
#endif
/*
Module: delay_10ms
Inserts program execution delay of aproximately 10 msec.
*/
#ifdef _D_10MS
void delay_10ms()
{
timer0_delay(1);
}
#endif
/*
Module: delay_0_1sec
Inserts program execution delay of aproximately one tenth second.
*/
#ifdef _D_01S
void delay_0_1sec(void)
{
timer0_delay(10);
}
#endif
/*
Module: delay_0_5sec
Inserts program execution delay of aproximately one half second.
*/
#ifdef _D_05S
void delay_0_5sec(void)
{
timer0_delay(50);
}
#endif
/*
Module: delay_1sec
Inserts program execution delay of aproximately 1 second.
*/
#ifdef _D_1S
void delay_1sec(void)
{
timer0_delay(100);
}
#endif
/*
Module: delay_2sec
Inserts program execution delay of aproximately 2 second.
*/
#ifdef _D_2S
void delay_2sec(void)
{
delay_1sec();
delay_1sec();
}
#endif
/*
Module: delay_10sec
Inserts program execution delay of aproximately 10 second.
*/
#ifdef _D_10S
void delay_10sec(void)
{
delay_2sec();
delay_2sec();
delay_2sec();
delay_2sec();
delay_2sec();
}
#endif
/*
Group: uPSD PWM Channels
Coverage: Initialize, Output, Disable
*/
/*
Module: uPSD_PWM_Init_8bit
Setup Prescaler value and I/O ports for the select channel of the 8-bit PWM.
*/
#ifdef _U_P_I_8
void uPSD_PWM_Init_8bit(unsigned char PWM_channel_no, unsigned char Duty_Cyl)
{
unsigned int PWM_prescaler;
switch (PWM_channel_no)
{
case 0:
{
P4SFS |= 0x08; /* output port P4[3] = PWM0 */
PWM0 = Duty_Cyl;
break;
}
case 1:
{
P4SFS |= 0x10; /* output port P4[4] = PWM1 */
PWM1 = Duty_Cyl;
break;
}
case 2:
{
P4SFS |= 0x20; /* output port P4[5] = PWM2 */
PWM2 = Duty_Cyl;
break;
}
case 3:
{
P4SFS |= 0x40; /* output port P4[6] = PWM3 */
PWM3 = Duty_Cyl;
break;
}
default:
break;
}
PWM_prescaler = (unsigned int ) (FREQ_OSC / (2 * PWM_freq8) - 1);
PSCL0L = PWM_prescaler;
PSCL0H = (PWM_prescaler >> 8);
}
#endif
/*
Module: uPSD_PWM_Channel_8bit
Output pulse train as specified in passed arguments
*/
#ifdef _U_P_C_8
void uPSD_PWM_Channel_8bit(unsigned char PWMCON_value, unsigned char PWM_channel_no, unsigned char Duty_Cyl)
{
unsigned char output_polarity_mode;
uPSD_PWM_Init_8bit(PWM_channel_no, Duty_Cyl); // Initialize
output_polarity_mode = PWMCON_value & 0x8F; // bit[7],bit[3:0]} are used to define PWM output mode
PWMCON |= output_polarity_mode; // 0--open drain; 1-- push pull
PWMCON |= 0x20; / /PWME = 1, Enable PWM IP
}
#endif
/*
Module: uPSD_PWM_Disable
Disable PWM IP
*/
#ifdef _U_P_D
void uPSD_PWM_Disable(void)
{
PWMCON &= 0xDF; //PWME = 0, Disable PWM output
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -