-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpga2310.h
104 lines (76 loc) · 1.87 KB
/
pga2310.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* pga2310.h
*
* Created: 2012/6/15 上午 09:06:47
* Author: Cherry_Yuan
*/
#ifndef PGA2310_H_
#define PGA2310_H_
/*
* SPI.h
*
* Created: 2011/11/24 22:59:10
* Author: Administrator
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include "switch.h"
#define SET_1(a,b) a|=(1<<b)
#define CLE_0(a,b) a&=~(1<<b)
/*
#define ZCEN_PORT PORTC
#define ZCEN_DDR DDRC
#define ZCEN PC3
*/
/*******************************************************************************/
/* PROCEDURE: HW_SPI_Init */
/* */
/* This procedure initializes the hardware SPI on the MCU. */
/* */
/* Input: None */
/* */
/* Returns: Nothing */
/* */
/*******************************************************************************/
void spiInit(void )
{
DDRB |= ((1<<PB2)|(1<<PB5)|(1<<PB3)); // Set MOSI , SCK , and SS output
//CLE_0(DDRB,6);
//CLE_0(PORTB,1);
SPCR = _BV(CPOL)|_BV(CPHA)|_BV(SPE)|_BV(MSTR)|_BV(SPR0)|_BV(SPR1);
SPSR |= _BV(SPI2X);
}
unsigned char spiByte(unsigned char addr)
{
SPDR = addr; //Load byte to Data register
while(!(SPSR & (1<<SPIF))); // Wait for transmission complete
return SPDR;
}
//#define SPIFLASH_CONFIG_CS DDRB |= (1<<PB2)
#define SPIFLASH_ASSERT_CS PORTB &= ~(1<<PB2)
#define SPIFLASH_RELEASE_CS PORTB |= (1<<PB2)
#define MUTE_CONFIG DDRB |=(1<<PB1)
#define MUTE PORTB &=~(1<<PB1)
#define uMUTE PORTB =(1<<PB1)
// functions
void Pga2310_port_Init(void)
{
// initialize spi
SPIFLASH_RELEASE_CS;
spiInit();
// initialize chip select
//SPIFLASH_CONFIG_CS;
MUTE_CONFIG;
MUTE;
}
void PGA2310_Write(unsigned char data)
{
// enable write
SPIFLASH_ASSERT_CS;
spiByte(data); //left
spiByte(data); //right
SPIFLASH_RELEASE_CS;
// clock out dummy byte to waste time
spiByte(0x00);
}
#endif /* PGA2310_H_ */