Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interfacing of AD7792 with PIC16f887

Status
Not open for further replies.

praveeshk

Newbie level 4
Joined
Sep 30, 2011
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
bangalore
Activity points
1,335
I hav trie to interface ad7792 with PIC16f887 n tried to display the o/p at lcd.but the program is not responding properly..the program in microC is listed below.. help me to find out the problem..



Code C - [expand]
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//******ADC connections**************************
#define cs_1 (PORTD.B4)
#define SCLK (PORTC.B3)
#define ADC_DIN (PORTC.B5) // DIN OF AD7792 connected to SDO of PIC
#define ADC_DOUT (PORTC.B4) //Dout OF AD7792 connected to SDI of PIC
#define Data_Ready (PORTC.B4) // DAta Ready pin is connected to PortC.B4
 
//************************************************** *************************
 
//********LCD Connections*************************************** ************
 
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
 
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
 
//************************************************** **************************
 
unsigned short buffer;
unsigned short Data1_H=0;
unsigned short Data1_L=0;
unsigned short Data2_H=0;
unsigned short Data2_L=0;
unsigned int v1=0;
unsigned int v2=0;
char text[7];
char text1[17]={'0','1','2','3','4','5','6','7','8','9','A','B', 'C','D','E','F'};
short temp;
char txt1[] = "V1=";
char txt2[] = "V2=";
//************************************************** ***************************
// Fun: for converting o/p value to corresponding text
 
void conv(int x)
{
temp=x;
text[5]=text1[temp&0x0f];
temp=x;
temp=temp>>4;
text[4]=text1[temp&0x0f];
x=x>>8;
temp=x;
text[3]=text1[temp&0x0f];
temp=temp>>4;
text[2]=text1[temp&0x0f];
text[1]='x';
text[0]='0';
text[6]='\0';
}
//************************************************** *********************
//fun for displaying in the LCD
 
void LCD_Display()
{
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,2,txt1); // Write text in first row
conv(v1);
Lcd_Out(1,5,text); // Write text in first row
Lcd_Out(2,2,txt2); // Write text in second row
conv(v2);
Lcd_Out(2,5,text); // Write text in second row
 
}
//************************************************** ***************
 
void init_all()
{
TRISA=0; PORTA=0; // configure portA as output
TRISB=0; PORTB=0; // configure portB as output
TRISC=0; PORTC=0; // configure portC as output
TRISD=0; PORTD=0; // configure portD as output
TRISE=0; PORTE=0; // configure portE as output
TRISC.B4=1;
ANSEL=0;
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
}
 
void get_ADC_output()
{
cs_1 = 0; //Select 1st ADC
SPI1_Write(0x08) ; //select mode_ reg
SPI1_write(0x00) ;
SPI1_write(0x01) ;
// selected internal 64KHz clk; continuous conv mode & update rate 500Hz
 
SPI1_write(0x10);//select config reg
SPI1_write(0x10);// Bias voltage generator disabled
//; unipolar;gain=1
SPI1_write(0x00); // selected channel 0
SPI1_write(0x5c); //select continuous conversion mode
 
if (Data_Ready == 0)
{
Data1_H = SPI1_Read(buffer);
Data1_L = SPI1_Read(buffer);
}
 
SPI1_write(0x10);//select config reg
SPI1_write(0x10);// Bias voltage generator disabled;
//unipolar;gain=1
SPI1_write(0x01); // selected channel 0
 
SPI1_write(0x5c); //select continuous conversion mode
 
if (Data_Ready == 0)
{
Data2_H = SPI1_Read(buffer);
Data2_L = SPI1_Read(buffer);
}
 
cs_1=1;
 
v1=Data1_H;
v1 = ((v1<<8)& 0xff);
v1=v1+ Data1_L;
v2=Data2_H;
v2=((v2<<8)& 0xff);
v2=v2+Data2_L;
 
}
 
 
 void main()
{
   init_all();
  SPI1_Init();
  Lcd_Init(); // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR); // Clear display
 
 while(1)
 
 {
 
 get_ADC_output();
 LCD_Display();
 
 }
 
 }

 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top