cs5460 with PIC16F877A

Status
Not open for further replies.

ajiths

Newbie level 1
Joined
Dec 3, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
bangalore
Activity points
1,308
Hi, everybody ,

I m new to this site.i m working with cs5460 with pic16f877a.the problem is my adc is not responding.The output is showing zero only.The hardware is ok,because the adc out is taken from a working weighscale board.i m attaching my code here.somebody please help.Thanks in advance....by Ajith.


#include<pic.h>
#define SDO RC0
#define SCLK RC1
#define SDI RC2
#define RESET RC3
const char seg[]={
0b11000000, //0 ************
0b11111001, //1 ************
0b10100100, //2 ************
0b10110000, //3
0b10011001, //4
0b10010010, //5
0b10000010, //6
0b11111000, //7 ARRAY SETTING
0b10000000, //8
0b10010000, //9
};
void write_reg(unsigned char command,unsigned char high,unsigned char mid,unsigned char low);
void write_data(unsigned char number);
void read_reg(unsigned char address);
char read_data(void);
int high_byte;
int mid_byte;
int low_byte;
unsigned char dispdigit[6];
unsigned char digitcount;
long h_data,t_data;
unsigned char fir_dec,sec_dec,thi_dec;
unsigned char four_dec,fift_dec,six_dec;
static void interrupt isr(void)
{
if (T0IF){
PORTB = dispdigit[digitcount];
PORTA = ~(1 << digitcount++);
if (digitcount > 5)
digitcount = 0; //DISPLAY SCANNING USING TIMER0//
TMR0 = 156;
T0IF = 0;
}
}

void main(void)
{
TRISA=0x00;
TRISB=0x00;
TRISC=0x01;
PORTA = 0x00;
PORTB = 0x00;
//PORTC = 0x00;
OPTION=0b00000100;
TMR0=156;
INTE=0;
INTF=0;
T0IE=1;
GIE=1;
RESET=0;
_delay(100);
RESET=1;
write_reg(0xFF, 0xFF, 0xFF, 0xFE);
write_reg(0x5E, 0x00, 0x00, 0x01); //status reg= 000001
write_reg(0x40, 0x00, 0x00, 0x04); //config reg= 000004
write_reg(0x4A, 0x00, 0x00, 0x32); //cycle count=000032
write_reg(0x78, 0x00, 0x00, 0x08); //control reg=000008
write_reg(0x74, 0x80, 0x00, 0x00); //mask reg= 800000
write_reg(0xE8,0xFE,0xFE,0xFE);

for(;
{
read_reg(0x0E);
high_byte=read_data(0);
mid_byte=read_data(0);
low_byte=read_data(0);
t_data=mid_byte;
t_data=t_data<<8;
h_data=low_byte;
h_data=t_data|h_data;

fir_dec=h_data%10;
h_data=h_data/10;
sec_dec=h_data%10;
h_data=h_data/10;
thi_dec=h_data%10;
h_data=h_data/10;
four_dec=h_data%10;
h_data=h_data/10;
fift_dec=h_data%10;
h_data=h_data/10;
six_dec=h_data%10;

dispdigit[0]=seg[fir_dec];
dispdigit[1]=seg[sec_dec];
dispdigit[2]=seg[thi_dec];
dispdigit[3]=seg[four_dec]; //to seven seg disp
dispdigit[4]=seg[fift_dec];
dispdigit[5]=seg[six_dec];
}
}


void read_reg(unsigned char address)
{
write_data(address);
return;
}
char read_data(void)
{
char x;
unsigned char sync=0xFE;
do
{
SDI=1;
_delay(100);
SCLK=1;
_delay(100);
SCLK=0;
_delay(100);
x=x | SDO;
x=x << 1;
sync=sync<<1;
}
while(sync);
SDI=0;
_delay(100);
SCLK=1;
_delay(100);
SCLK=0;
_delay(100);
x=x | SDO;
return x;
}

void write_reg(unsigned char command,unsigned char high,unsigned char mid,unsigned char low)
{
write_data(command);
write_data(high);
write_data(mid);
write_data(low);
}
void write_data(unsigned char number)
{
unsigned char counter;
counter=0x08;
while(counter)
{
if(number & 0x80)
{
SDI=1;
_delay(100);
}
else
{
SDI=0;
_delay(100);
}
SCLK=1;
_delay(100);
SCLK=0;
_delay(100);
number=number<<1;
_delay(100);
--counter;
}
return;
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…