C51 COMPILER V7.05   DAC                                                                   08/10/2011 18:35:33 PAGE 1   


C51 COMPILER V7.05, COMPILATION OF MODULE DAC
OBJECT MODULE PLACED IN DAC.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE DAC.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          //-----------------------------------------------------------------------------------------------------//
   2          // PROJECT NAME  -   DAC WITH I2C PROTOCOL
   3          // AUTHOR MAIL     - bhau2727@gmail.com
   4          // DATE OF ALTERED - 27/7/2011
   5          // HARDWARE        - PCF 8591 WITH P89V51RD2 BASED 
   6          // SOFTWARE        - INPUTS   HIGH LEVEL - 1 // LOW LEVEL - 0 //READ THE RESULT AT DAC PIN ON BOARD
   7          //-----------------------------------------------------------------------------------------------------//
   8          //----------------------------------HEADER Declarations--------------------------------------//
   9          #include <reg51.h>
  10          
  11          #include "dac8591.h"
  12          
  13          //----------------------------------LCD Declarations--------------------------------------//
  14          void initlcd(void);
  15          void cmd_lcd(unsigned char command);
  16          void data_lcd(unsigned char data2lcd);
  17          void lcd_shortdelay(void);
  18          void delay_ms(unsigned char milliseconds);
  19          void printnum_lcd(unsigned char message, unsigned char row, unsigned char col);  //ascii to decimal
  20          void printlcd(unsigned char *message, unsigned char row, unsigned char col);
  21          
  22          sbit enable=P3^4;
  23          sbit regsel=P3^5;
  24          #define LCD_PORT P1
  25          
  26          #define CLR_LCD cmd_lcd(0x01); delay_ms(5)
  27          #define RETURN_HOME_LCD cmd_lcd(0x02); delay_ms(5)  
  28          
  29          void delay_ms(unsigned char milliseconds);
  30          //----------------------------------MAIN program--------------------------------------//
  31          
  32          main()
  33          {
  34   1              
  35   1      
  36   1              initlcd();                                                                      //lcd initialization
  37   1              printlcd("DAC TEST...",0,0);
  38   1          while(1)
  39   1          {
  40   2                      int d = 0x50;
  41   2                  cmd_lcd(0x0c);                                              //cursor off
  42   2                      for(;d<0xa0;d++)
  43   2                      {
  44   3                              if(d >=0x10)
  45   3                              i2c_write(0x9E,0x40,d);                         //write DAC RESULT to chip
  46   3                              delay_ms(15);
  47   3                      }
  48   2                      //d++;
  49   2                      for(d=0xa0;d>0x50;d--)
  50   2                      {
  51   3      
  52   3                              i2c_write(0x9E,0x40,d);                         //write DAC RESULT to chip
  53   3                              delay_ms(15);
  54   3                      }
  55   2              
C51 COMPILER V7.05   DAC                                                                   08/10/2011 18:35:33 PAGE 2   

  56   2              }
  57   1      }
  58          
  59          
  60          //----------------------------------Init lcd--------------------------------------//
  61          void initlcd()
  62          {
  63   1              enable=0;
  64   1              delay_ms(20);
  65   1              cmd_lcd(0x30);
  66   1              delay_ms(5);
  67   1              cmd_lcd(0x30);
  68   1              cmd_lcd(0x30);
  69   1              cmd_lcd(0x38);
  70   1              cmd_lcd(0x08);
  71   1              CLR_LCD;
  72   1              cmd_lcd(0x06);
  73   1              cmd_lcd(0x0e);
  74   1      }
  75          
  76          void cmd_lcd(unsigned char command)
  77          {
  78   1              LCD_PORT=command;
  79   1              regsel=0;
  80   1              enable=1;
  81   1              enable=0;
  82   1              lcd_shortdelay();
  83   1      }
  84          void data_lcd(unsigned char databyte)
  85          {       
  86   1              LCD_PORT=databyte;
  87   1              regsel=1;
  88   1              enable=1;
  89   1              enable=0;
  90   1              lcd_shortdelay();
  91   1      }
  92          void lcd_shortdelay(void)
  93          {
  94   1              unsigned char t=23;
  95   1              while(t--);
  96   1      }
  97                  
  98          void delay_ms(unsigned char ms)
  99          {
 100   1              unsigned char t1;
 101   1              unsigned int t2;
 102   1      
 103   1              for(t1=0; t1<ms; t1++){
 104   2                      for(t2=0; t2<711; t2++);
 105   2              }
 106   1      }
 107          void printlcd(unsigned char *message, unsigned char row, unsigned char col)
 108          {
 109   1         cmd_lcd(0x80 + (0x40*row) + col);
 110   1         
 111   1         for(; *message; message++)
 112   1            data_lcd(*message);
 113   1         
 114   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
C51 COMPILER V7.05   DAC                                                                   08/10/2011 18:35:33 PAGE 3   

   CODE SIZE        =    430    ----
   CONSTANT SIZE    =     12    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       7
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
