LM35DZ Sensor and PIC18F4550

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

LM35DZ Sensor and PIC18F4550

Postby Nagen Daksh » Mon Jan 14, 2013 1:21 am

Hello to everyone,

I'm seeking for a program that can be used for PIC18F4550 to display the temperature in LCD. I have already search the topics in this forum regarding this subject but couldn't find it. In Cytron website there is a project regarding this but it specifies for 16F877(Project 5 in Cytron main website)? Could anybody help me to give any suitable program that can be display temperature using the 18F4550... :)
Nagen Daksh
Freshie
 
Posts: 6
Joined: Mon Jan 14, 2013 1:06 am

Re: LM35DZ Sensor and PIC18F4550

Postby ober » Sun Jan 20, 2013 8:59 pm

We do not have sample of reading LM35 and display it on LCD with 18F4550.

Anyway a good way to learn is get a template or sample program for PIC18F4550 (you can try downloading some sample code under SK40C page). Make sure you can compile and load into your board, also it can display message on LCD.

From there, develop the code for ADC and read LM35.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: LM35DZ Sensor and PIC18F4550

Postby Nagen Daksh » Mon Jan 21, 2013 12:09 am

Thanks for your kind reply Mr.Ober. But sir, myself are not good in handling PIC184550 because it is a new attempt for me too.I'm more perefer to use PIC16F877A because I'm familiar with that but unfortunately my situation makes me to use PIC18F. So sir, could you help to create or some example of codes. I'm really need it. :)
Nagen Daksh
Freshie
 
Posts: 6
Joined: Mon Jan 14, 2013 1:06 am

Re: LM35DZ Sensor and PIC18F4550

Postby yonghui » Mon Jan 21, 2013 11:00 am

I think the tutorial website of Cytron has example for sk40 LCD display project , u Can Refer The code to get start.
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: LM35DZ Sensor and PIC18F4550

Postby Brian Griffin » Mon Jan 21, 2013 1:19 pm

There is not much of a difference from a PIC16F to a PIC18F. And, it's not like you are writing the same code for a Motorola processor.
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: LM35DZ Sensor and PIC18F4550

Postby Nagen Daksh » Mon Jan 21, 2013 6:25 pm

Thanks for the kind replies guys. As yonghui said, I have tried most of the codes in cytron website itself and other codes at different source. A the result all the LED source code that I've tried using sk40 are successful. But when it comes to LCD,I'm quite blur because although i could compile it but I cannot display it. Only black box appear. I have go through all the notes given by cytron and I think my connection are right too. But maybe there is some mistakes I've done during the compiling process.Hence there is few question that I would like to ask?

If the input port is set at Port B and the output is PORT D, should i use a jumper to connect it?(*not too familiar with sk40c port usage and how actually it work)

this is an example of my code for PIC18F4550 :

CODE: SELECT_ALL_CODE
   //LCD Display Program
   //P1(LCD -data)=PB, P2(LCD reg)=PD

   #include<htc.h>

   #define RS   RD0
   #define RW   RD1
   #define EN   RD2

   void LCD_delay(void)
   {
   int t;
   for(t=0;t<250;t++);
   }

   
   void delay_ms(unsigned char delay)
   {
   unsigned int i,j;
   for(i=0;i<=delay;i++);
   {
   for(j=0;j<=1000;j++);
   }
   }

   void LCD_command(unsigned char command)
   {
   unsigned char temp;
   RS=0;

   temp=command & 0xff;
   PORTB&=0x00;
   PORTB|=temp;
   EN=1;
   for(temp=0;temp<5;temp++);
   EN=0;
   LCD_delay();
   }
   
   void LCD_data(unsigned char data)
   {
   unsigned char temp;
   RS=1;
   temp=data & 0xff;
   PORTB&=0x00;
   PORTB|=temp;
   EN = 1;
   for(temp=0;temp<5;temp++);
   EN=0;
   LCD_delay();
   }

   void initialise_LCD(void)
   {
   TRISB = 0x00;
   PORTB = 0x00;

   TRISD = 0x00;
   PORTD = 0x00;
   EN=0;
   RW=0;
   
      delay_ms(40);
      LCD_command(0x38);
      delay_ms(20);
      LCD_command(0x38);
      delay_ms(2);
      LCD_command(0x38);
      delay_ms(1);
      
      LCD_command(0x07);
      LCD_command(0x0c);
      LCD_command(0x14);
      LCD_command(0x02);
      LCD_command(0x01);
      delay_ms(1);
   }
   
   void clear_LCD()
   {
      LCD_command(0x01);
      delay_ms(1);
   }

   void display_LCD(char line_number, char position,const char*message)
   {
      int a;
      if(line_number==1)
   {
      a=0x80+position;
      LCD_command(a);
   }
      else if(line_number==2)
   {
      a=0xC0+position;
      LCD_command(a);
   }
      while(*message);
   {
      LCD_data(*message);
      delay_ms(15);
      message++;
   }
   }   
   
   void main(void)
   {
   
   __CONFIG(0x193A);
   initialise_LCD();
   while(1)
   {
   display_LCD(1,8, "Welcome to ");
   display_LCD(2,10, "Cytron Forum");
   delay_ms(1);
   }
    }
   

* This code will work well if I use PIC16F877A

Could anyone help to fix this code so that it can be compiled using High C Pro TECH PIC18, for PIC18F4550? (*Help indeed very much)
Nagen Daksh
Freshie
 
Posts: 6
Joined: Mon Jan 14, 2013 1:06 am

Re: LM35DZ Sensor and PIC18F4550

Postby shahrul » Mon Jan 21, 2013 8:27 pm

Check configuration bits for PIC18F4550. This is an example
CODE: SELECT_ALL_CODE
#include <htc.h>
#if defined (_16F777)
   __CONFIG(FOSC_HS & WDTE_OFF & PWRTE_ON & BOREN_OFF & MCLRE_ON & CCP2MX_RC1);
   __CONFIG(FCMEN_OFF & IESO_OFF);
   #define _XTAL_FREQ    20000000
#elif defined (_16F877A)
   __CONFIG(FOSC_HS & WDTE_OFF & PWRTE_ON & BOREN_OFF & LVP_OFF);
   #define _XTAL_FREQ    20000000
#elif defined (_16F887)
   __CONFIG(FOSC_HS & WDTE_OFF & PWRTE_ON & BOREN_OFF & CP_ON & MCLRE_ON &   LVP_OFF);
   #define _XTAL_FREQ    20000000
#elif defined (_18F4520)
   __CONFIG(1,HS & FCMDIS & IESODIS);
   __CONFIG(2,PWRTEN & BOREN & BORV20 & WDTDIS & WDTPS32K);
   __CONFIG(3,CCP2RC1 & PBADDIS & LPT1DIS & MCLREN);
   __CONFIG(4,XINSTDIS & STVREN & LVPDIS & DEBUGDIS);
   __CONFIG(5,UNPROTECT);
   __CONFIG(6,UNPROTECT);
   __CONFIG(7,UNPROTECT);
   #define _XTAL_FREQ    20000000
#elif defined (_18F4550)
   __CONFIG(1,USBOSC & CPUDIV1 & PLLDIV5 & HSPLL  & FCMDIS & IESODIS);
   __CONFIG(2,VREGEN & PWRTEN & BOREN & BORV20 & WDTDIS & WDTPS32K);
   __CONFIG(3,CCP2RC1 & PBADDIS & LPT1DIS & MCLREN);
   __CONFIG(4,XINSTDIS & STVREN & LVPDIS & ICPORTDIS & DEBUGDIS);
   __CONFIG(5,UNPROTECT);
   __CONFIG(6,UNPROTECT);
   __CONFIG(7,UNPROTECT);
   #define _XTAL_FREQ    48000000
#elif defined (__dsPIC30F4013__)
   __CONFIG(FOSC, HS);
   __CONFIG(FWDT, WDTDIS);
   __CONFIG(FBORPOR, MCLREN & BORDIS & PWRT64);
   __CONFIG(FGS, GCPU & GWRU);
   __CONFIG(FICD, PGEMU);
   #define _XTAL_FREQ    20000000
#else
   #error PIC not support
#endif
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: LM35DZ Sensor and PIC18F4550

Postby Nagen Daksh » Tue Jan 22, 2013 7:55 pm

Thanks for your kind reply Mr.Shahrul. Appreciate it very much. I have visit your site and I found there is a project similar to the topic about the temperature sensor. Could i get the source code and the ways you make to happen including the method to do PIC development board manually? :)
Nagen Daksh
Freshie
 
Posts: 6
Joined: Mon Jan 14, 2013 1:06 am

Re: LM35DZ Sensor and PIC18F4550

Postby shahrul » Tue Jan 22, 2013 8:15 pm

Nagen Daksh WROTE:Thanks for your kind reply Mr.Shahrul. Appreciate it very much. I have visit your site and I found there is a project similar to the topic about the temperature sensor. Could i get the source code and the ways you make to happen including the method to do PIC development board manually? :)

Source code project not for free.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: LM35DZ Sensor and PIC18F4550

Postby Nagen Daksh » Wed Jan 23, 2013 6:21 pm

shahrul WROTE:
Nagen Daksh WROTE:Thanks for your kind reply Mr.Shahrul. Appreciate it very much. I have visit your site and I found there is a project similar to the topic about the temperature sensor. Could i get the source code and the ways you make to happen including the method to do PIC development board manually? :)

Source code project not for free.


How much do you sold it together with the manually done PIC development board?
Nagen Daksh
Freshie
 
Posts: 6
Joined: Mon Jan 14, 2013 1:06 am

Next

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 3 guests