View previous topic :: View next topic |
Author |
Message |
shekhu4u
Joined: 17 Aug 2011 Posts: 1
|
ADC program help needed |
Posted: Wed Aug 17, 2011 12:47 pm |
|
|
Here I am trying to do A/D conversion and transfer the data to putty, to see the output but it seems it's not working. Need your help guys.........
My code:
Code: |
#include <htc.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
main()
{
int j,x,y,z;
OSCCON=0x70;
CMCON0=0X07; //turn off comparator
TRISA=0X01; //input port
ADCON1=0X50; //fosc/16
ADCON0=0x81; // right justufied
INTCON=0X00;
ANSEL=0x01;// select channel
TMR2=0X00; //clear tmr2
TRISB=0x00;
PORTB=0x00;
TRISC = 0x00;//
PORTC = 0x00; // CLEAR DATA LATCH
//TXSTA=0x24;
T2CON = 0x04; // POSTSCALER 1:1, PRESCALER 1:1, TIMER2 ON
//serial communication
RCSTA=0X80;
SPBRG=0x0C; //baudrate 9600
PIE1=0X00;
// TXSTA=0X20;
while(1)
{
for (j=1; j<3;j++)
{
ANSEL=j;
if(j==1)
{
ADCON0=0x81;
}
else{
ADCON0=0x85;
}
ADCON0=ADCON0|0X02;
if ((ADCON0&0x02)!=0X02)
{
TXREG=ADRESL;
TXSTA=0x20;
if((TXSTA&0X22)!=0X22);
TXREG=ADRESH;
TXSTA=0X20;
if((TXSTA&0X22)!=0X22); //hold till tx completess
}
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed Aug 17, 2011 1:43 pm |
|
|
or...
you could just use the example in the ccs C compiler examples folder as a basis of using CCS C, then you will get help here ! |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Aug 17, 2011 3:11 pm |
|
|
I have believed for a LONG time - after trying it - initially -
that it is so simplistically assembler derived -
that LOW tech C was a much more apt name.
I started work with PICs in assembler - and LOWtech C
was just not enough of an improvement for me to bother with.
and the lowtech forum?? whew - blind leading blind ... ;-))
just my 2 cents |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Thu Aug 18, 2011 3:52 pm |
|
|
asmboy wrote: |
and the lowtech forum?? whew - blind leading blind ... ;-))
just my 2 cents |
Asm, you crack me up.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|