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.

PIC18F4XK20 Starter Kit

Status
Not open for further replies.

jmie

Newbie level 4
Joined
Dec 9, 2009
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,349
hi guys!!

i just brought PIC18F4XK20 Starter Kit for my project..The MCP9700 temperature sensor is located on the board. So, how to integrate an analogue temperature sensor into system? how to interface between temperature sensor and MCU? Is it have source code to operate temperature sensor??

please help me..thanks a lot
 

wp100

Advanced Member level 5
Joined
May 15, 2009
Messages
3,051
Helped
883
Reputation
1,781
Reaction score
733
Trophy points
113
Location
Prime Meridian
Activity points
0
Hi,

Well you have a really nice development board there with the good old Pickit2 programmer.

You realy need to spend some time looking at the schematics and reading the user guides and you will see that most ports are free to be used as you want.

You do not say if you are doing Assember or C or what kind of analogue temp sensor you are wanting to use ? - but in a word, yes you can run anything on to that board.

The most basic analogue sensor would be a 10k trimmer pot on RA0.
 

jmie

Newbie level 4
Joined
Dec 9, 2009
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,349
hi,


thanks wp100 because reply..

somebody have example source code to run temperature sensor???
 

jmie

Newbie level 4
Joined
Dec 9, 2009
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,349
this is the source code to run temperatur sensor..plz checking if there is wrong with this code..

/** I N C L U D E S **************************************************/
#include "p18f46k20.h"
#include "07 ADC.h" // header file

/** V A R I A B L E S *************************************************/
#pragma udata // declare statically allocated uinitialized variables
unsigned char LED_Display; // 8-bit variable

/** D E C L A R A T I O N S *******************************************/
#pragma code // declare executable instructions

void main (void)
{
LEDDirections Direction = LEFT2RIGHT;
BOOL SwitchPressed = FALSE;

LED_Display = 1; // initialize

// Init I/O
TRISD = 0b00000000; // PORTD bits 7:0 are all outputs (0)
TRISEbits.TRISE1 = 1; // TRISE1 input

INTCON2bits.RBPU = 0; // enable PORTB internal pullups
WPUBbits.WPUB0 = 1; // enable pull up on RB0

// ADCON1 is now set up in the InitADC() function.
TRISBbits.TRISB0 = 1; // PORTB bit 0 (connected to switch) is input (1)

// Init Timer0
Timer0_Init();

// Init ADC
ADC_Init();

while (1)
{

if (Direction == LEFT2RIGHT)
{
LED_Display <<= 1; // rotate display by 1 from 0 to 7
if (LED_Display == 0)
LED_Display = 1; // rotated bit out, so set bit 0
}
if (Direction == RIGHT2LEFT)
{
LED_Display >>= 1; // rotate display by 1 from 7 to 0
if (LED_Display == 0)
LED_Display = 0x80; // rotated bit out, so set bit 7
}

LATD = LED_Display; // output LED_Display value to PORTD LEDs

do
{ // poll the switch while waiting for the timer to roll over.
if (Switch_Pin == 1)
{ // look for switch released.
SwitchPressed = FALSE;
}
else if (SwitchPressed == FALSE) // && (Switch_Pin == 0) due to if-else
{ // switch was just pressed
SwitchPressed = TRUE;
// change direction
if (Direction == LEFT2RIGHT)
Direction = RIGHT2LEFT;
else
Direction = LEFT2RIGHT;
}

} while (INTCONbits.TMR0IF == 0);

// Timer expired
INTCONbits.TMR0IF = 0; // Reset Timer flag

// Take an ADC conversion and use it to set Timer0
TMR0H = ADC_Convert(); // MSB from ADC
TMR0L = 0; // LSB = 0

}

}

void Timer0_Init(void)
{
INTCONbits.TMR0IF = 0; // clear roll-over interrupt flag
T0CON = 0b00000001; // prescale 1:4 - about 1 second maximum delay.
TMR0H = 0; // clear timer - always write upper byte first
TMR0L = 0;
T0CONbits.TMR0ON = 1; // start timer
}
void ADC_Init(void)
{
ANSEL = 0; //turn off all other analog inputs
ANSELH = 0;
ANSELbits.ANS6 = 1; // turn on RE1 analog

// Special Function Register
ADCON2 = 0b00111000;

// Select channel 6 (AN6) to read the temperature sensor voltage and turn on ADC
ADCON0 = 0b00011001;
}

unsigned char ADC_Convert(void)
{ // start an ADC conversion and return the 8 most-significant bits of the result
ADCON0bits.GO_DONE = 1; // start conversion
while (ADCON0bits.GO_DONE == 1); // wait for it to complete
return ADRESH; // return high byte of result
}


tq...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top