PR11 Programing Question

LED Blinking, Walking with Cytron Servo, Displaying RFID, Multi-function Mobile Robot......

PR11 Programing Question

Postby non » Sun Mar 06, 2011 12:56 am

Hi Cytron,

I'm new in PIC program.I need help to understanding the program that you have provide on the PR11. I need to change the result for the pr11 as it show around +/- 100Celcius at room temperature. How can i adjust back to room temperature and which part of the program i need to change. Thank You.
non
Freshie
 
Posts: 4
Joined: Sun Mar 06, 2011 12:40 am

Re: PR11 Programing Question

Postby ABSF » Sun Mar 06, 2011 10:43 am

non WROTE:Hi Cytron,

I'm new in PIC program.I need help to understanding the program that you have provide on the PR11. I need to change the result for the pr11 as it show around +/- 100Celcius at room temperature. How can i adjust back to room temperature and which part of the program i need to change. Thank You.


Read the "PR11_DD.pdf" on page 2 and page 3 carefully. Your answers are all there!

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: PR11 Programing Question

Postby non » Thu Mar 10, 2011 8:48 pm

ya, i had see its.(10mV=1 celcius) Actually in the program, where do i need to moditified in the program??
non
Freshie
 
Posts: 4
Joined: Sun Mar 06, 2011 12:40 am

Re: PR11 Programing Question

Postby hyng » Fri Mar 11, 2011 9:34 am

non WROTE:Hi Cytron,

I'm new in PIC program.I need help to understanding the program that you have provide on the PR11. I need to change the result for the pr11 as it show around +/- 100Celcius at room temperature. How can i adjust back to room temperature and which part of the program i need to change. Thank You.


It shouldn't be 100 celcius at room temperature. Please try to adjust the preset (label as offset) on the circuit.
User avatar
hyng
Moderator
 
Posts: 292
Joined: Thu Apr 16, 2009 11:35 am

Re: PR11 Programing Question

Postby non » Fri Mar 11, 2011 11:53 am

thanks ya, i already getting the room temperature. but if i want to locate the formula to program.where should i put?? I means that if i don't wan to use the preset button to adjust, where and what should i program in the PIC ??
non
Freshie
 
Posts: 4
Joined: Sun Mar 06, 2011 12:40 am

Re: PR11 Programing Question

Postby hyng » Fri Mar 11, 2011 2:06 pm

Refer to the schematic, offset pin is connected to RA3/Vref+. Therefore, it should be for ADC voltage reference purpose in ADC mode. You can't give any value to this pin inside the program , you can only set the configuration at the ADCON1 register (pls refer to datasheet).
User avatar
hyng
Moderator
 
Posts: 292
Joined: Thu Apr 16, 2009 11:35 am

Re: PR11 Programing Question

Postby non » Sun Mar 20, 2011 5:47 pm

Hi ;

I need to change the chip to pic16F887 but i cant show any result on the lcd , it show black box on the first line. Please help me on this program~~~

CODE: SELECT_ALL_CODE
#define      lcd         PORTD
#define      RS         RE2
#define    RW         RE0
#define      E         RB0
#define      CHANNEL0      0x41   // AN0
//#define      buzzer      RB5
//#define      fanA      RB4
//#define      fanB      RB3
//#define      ledA      RB2
//#define      ledB      RB1

//==============FUNCTION PTOTOTYPE=========================
void e_pulse(void);
void delay(unsigned short i);
void send_char(unsigned char data);
void send_config(unsigned char data);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void dis_num(unsigned long data);
void increment(unsigned long data);
void read_adc(void);
unsigned short read_temp(void);

//====================MAIN================================
unsigned short result;
unsigned short temp,tempA;

void main(void)
{
   ADRESH=0;               //clear A/D result
   ADRESL=0;               //clear A/D result

   //setting ADCON1 Register
   ADCON1=0x90;         // A/D result right justified,             
                        // configure RA2 and RA5 as digital I/O
   ANSEl=0xFF;
   TRISA=0x0F;         //configure PORTA I/O direction
   TRISB=0x00;         //configure PORTB as output
   TRISC=0x00;         //configure PORTC as output
   TRISD=0b00000000
   TRISE=0;
   PORTA=0;
   while(1)               
   {
      send_config(0b00000001);      //clear display at lcd
      send_config(0b00000010);      //Lcd Return to home
      send_config(0b00000110);      //entry mode-cursor increase 1
      send_config(0b00001100);      //diplay on, cursor off and cursor blink off
      send_config(0b00111000);      //function set
      
      lcd_goto(0);               //cursor start from beginning
      
      //display character on LCD
      send_char(' ');
      send_char('T');
      send_char('E');
      send_char('M');
      send_char('P');
      send_char('.');
      send_char(' ');
      send_char('=');   
   
      while(1)                  //infinity loop
      {
      //sensor A
      ADCON0=CHANNEL0;            //CHANNEL1=0b10001001
      lcd_goto(8);
            
      read_adc();

      temp=read_temp();
      dis_num(temp/10);
      send_char('.');
      dis_num(temp%10);
      send_char(0b11011111);
      send_char('C');
      send_char(' ');
      send_char(' ');
      
      tempA=temp;
   
      }
   
   }
      
}
      
               

//==================subroutine LCD setting ==========================

void send_config(unsigned char data)
{
    RW=0
   RS=0;
   lcd=data;
   delay(500);
   e_pulse();
}

void e_pulse(void)
{
   E=1;
   delay(500);
   E=0;
   delay(500);
}

void send_char(unsigned char data)
{
    RW=0
   RS=1;
   lcd=data;
   delay(500);
   e_pulse();
}


void lcd_goto(unsigned char data)
{
    if(data<16)
   {
       send_config(0x80+data);
   }
   else
   {
       data=data-20;
      send_config(0xc0+data);
   }
}


void lcd_clr(void)
{
    send_config(0x01);
   delay(600);   
}


void dis_num(unsigned long data)
{
   unsigned char hundred_thousand;
   unsigned char ten_thousand;
   unsigned char thousand;
   unsigned char hundred;
   unsigned char tenth;

   hundred_thousand = data/100000;               
   data = data % 100000;
   ten_thousand = data/10000;
   data = data % 10000;
   thousand = data / 1000;
   data = data % 1000;
   hundred = data / 100;
   data = data % 100;
   tenth = data / 10;
   data = data % 10;

   if(hundred_thousand>0)
   {
      send_char(hundred_thousand + 0x30);   //0x30 added to become ASCII code
      send_char(ten_thousand + 0x30);
      send_char(thousand + 0x30);
      send_char(hundred + 0x30);
      send_char(tenth + 0x30);
      send_char(data + 0x30);
   }

   else if(ten_thousand>0)
   {
      send_char(ten_thousand + 0x30);   //0x30 added to become ASCII code
      send_char(thousand + 0x30);
      send_char(hundred + 0x30);
      send_char(tenth + 0x30);
      send_char(data + 0x30);
   }
   else if(thousand>0)
   {
       send_char(thousand + 0x30);   //0x30 added to become ASCII code
      send_char(hundred + 0x30);
      send_char(tenth + 0x30);
      send_char(data + 0x30);
   }
   else if(hundred>0)
   {
       send_char(hundred + 0x30);   //0x30 added to become ASCII code
      send_char(tenth + 0x30);
      send_char(data + 0x30);
   }
   else if(tenth>0)
    {
      send_char(tenth + 0x30);   //0x30 added to become ASCII code
      send_char(data + 0x30);
   }
   else send_char(data + 0x30);   //0x30 added to become ASCII code
}

void increment(unsigned long data)
{   
   unsigned short j;
   for(j=10;j>0;j--)
   {   lcd_goto(32);
      data=data+1;
      dis_num(data);
      delay(10000);
   }

}

//==================subroutine ADC=========================

void read_adc(void)
{
   unsigned short i;
   unsigned long result_temp=0;
   for(i=2000;i>0;i-=1)         //looping 2000 times for getting average value
   {
      GODONE = 1;               //ADGO is the bit 2 of the ADCON0 register
      while(GODONE==1);            //ADC start, ADGO=0 after finish ADC progress
      result=ADRESH;
      result=result<<8;         //shift to left for 8 bit
      result=result|ADRESL;      //10 bit result from ADC

      result_temp+=result;      
   }
   result = (result_temp/1000)*1.8;      //getting average value
}
unsigned short read_temp(void)
{
   unsigned short temp;
   temp=result;
   return temp;

}
//==================subroutine DELAY==========================
void delay(unsigned short i)
{   
   for(;i>0;i--);
}
non
Freshie
 
Posts: 4
Joined: Sun Mar 06, 2011 12:40 am

Re: PR11 Programing Question

Postby kl84 » Sat Mar 26, 2011 11:15 am

Have you change the device in MPLAB to 16F887? Configure >> Select Device >> PIC16F887.

Can you successfully build/compile your code? Can you successfully program your PIC? I don't see #include <htc.h> and configuration bits in your program...
User avatar
kl84
Amateur
 
Posts: 166
Joined: Thu Jul 08, 2010 12:14 pm


Return to DIY Project Set

Who is online

Users browsing this forum: No registered users and 14 guests