Haberler:

Forum kuralları güncellendi LÜTFEN  okuyunuz:  https://bit.ly/2IjR3ME

Ana Menü

lcd frekansmetre

Başlatan necati, 18 Mayıs 2007, 22:52:52

necati

#include <16f628.H>
#use   delay(clock=4000000)//frq in pin b6
#fuses NOPROTECT,NOWDT,PUT,noBROWNOUT,noLVP,NOMCLR,xt
#BYTE     PORT_A=0X05
#BYTE     PORT_B=0X06
/***entegreterbiyecisi@yahoo.com***//***entegreterbiyecisi@yahoo.com***/
// LCD STUFF
#define LCD_RS      PIN_b0
#define LCD_EN      PIN_b1
#define LCD_D4      PIN_b2
#define LCD_D5      PIN_b3
#define LCD_D6      PIN_b4
#define LCD_D7      PIN_b5
#define FIRST_LINE  0x00
#define SECOND_LINE 0x40
#define CLEAR_DISP  0x01
#define CURS_ON     0x0e
#define CURS_OFF    0x0c
/***entegreterbiyecisi@yahoo.com***/
#use standard_io ( a )
#use standard_io ( b )
/***entegreterbiyecisi@yahoo.com***/
// proto statements
void LCD_Init        ( void );
void LCD_SetPosition ( unsigned int cX );
void LCD_PutChar     ( unsigned int cX );
void LCD_PutCmd      ( unsigned int cX );
void LCD_PulseEnable ( void );
void LCD_SetData     ( unsigned int cX );
/***entegreterbiyecisi@yahoo.com***//***entegreterbiyecisi@yahoo.com***/
/*************************entegreterbiyecisi@yahoo.com******************************/
int32 ab=0,hz=0;
int1 stept_say=0,data_bitti=0,step,aa=0;
int16 sayi=0,tr=20;
/*************************entegreterbiyecisi@yahoo.com******************************/
#int_timer1
tas(){
ab++;
}
#int_timer0
sn(){sayi=0;
set_timer0(61);//(255-60)*195*20=1000000us=dahili 1sn icin
if(tr){ tr--;}
else{delay_us ( 698 );
     output_low(pin_a0);
     disable_interrupts (global);
     disable_interrupts(int_timer0);
     disable_interrupts(int_timer1);
     sayi=get_timer1();
     aa=1;
     hz=sayi+(65536*ab);
     tr=20;
                             }}
/*************************entegreterbiyecisi@yahoo.com******************************/
  void main() {

     setup_timer_1(t1_external|t1_div_by_1);
     setup_timer_0 (RTCC_INTERNAL|RTCC_DIV_256);
     enable_interrupts(int_timer0); // timer0
     enable_interrupts(int_timer1);
     enable_interrupts(global);
     lcd_init();
     SET_TRIS_A(0b00100000);
     SET_TRIS_B(0b11000000);
     set_timer0(61);
     set_timer1(0);

     LCD_SetPosition(first_LINE+0);
     printf(lcd_putchar,"\NECATi KIYLIOGLU ");
     LCD_SetPosition(second_LINE+1);
     printf(lcd_putchar,"\ 0532 613 65 87");
     delay_ms (500);
     LCD_PutCmd ( CLEAR_DISP );
     sayi=0;
     hz=0;
/*************************entegreterbiyecisi@yahoo.com******************************/
while(true){
  if(aa==1){
     //LCD_PutCmd ( CLEAR_DISP );
     LCD_SetPosition(first_LINE+0);
     printf(lcd_putchar,"\FREQUENCYMETER     ");

   if(999>=hz){
     LCD_SetPosition(second_LINE+0);
     printf(lcd_putchar,"\FRQ=%ldHz          ",hz);}
     //////////////////////////////////////////
   if(hz>=1000){
   if(999999>=hz){
     LCD_SetPosition(second_LINE+0);
     printf(lcd_putchar,"\FRQ=%3.3wKhz         ",hz);}}
     /////////////////////////////////////////////
   if(hz>=1000000){
     LCD_SetPosition(second_LINE+0);
     printf(lcd_putchar,"\FRQ=%2.6wMhz          ",hz);}
     ////////////////////////////////////////////
     delay_ms (1);

     set_timer1(0);
     enable_interrupts(int_timer0);
     enable_interrupts(int_timer1);
     enable_interrupts (global);
     aa=0;
     ab=0;
     }
            }}
/*************************entegreterbiyecisi@yahoo.com******************************/
/***entegreterbiyecisi@yahoo.com***/ //lcd basla
void LCD_Init ( void ){
   LCD_SetData ( 0x00 );
   output_low ( LCD_RS );
   LCD_SetData ( 0x03 );   // init with specific nibbles to start 4-bit mode
   LCD_PulseEnable();
   LCD_PulseEnable();
   LCD_PulseEnable();
   LCD_SetData ( 0x02 );   // set 4-bit interface
   LCD_PulseEnable();      // send dual nibbles hereafter, MSN first
   LCD_PutCmd ( 0x2C );    // function set (all lines, 5x7 characters)
   LCD_PutCmd ( 0x0C );    // display ON, cursor off, no blink
   LCD_PutCmd ( 0x01 );    // clear display
   LCD_PutCmd ( 0x06 );    // entry mode set, increment
   }
/***entegreterbiyecisi@yahoo.com***/
void LCD_SetPosition ( unsigned int cX )
   {
   // this subroutine works specifically for 4-bit Port A
   LCD_SetData ( swap ( cX ) | 0x08 );
   LCD_PulseEnable();
   LCD_SetData ( swap ( cX ) );
   LCD_PulseEnable();
   }
/***entegreterbiyecisi@yahoo.com***/
void LCD_PutChar ( unsigned int cX )
   {
   // this subroutine works specifically for 4-bit Port A
   output_high ( LCD_RS );
   LCD_SetData ( swap ( cX ) );     // send high nibble
   LCD_PulseEnable();
   LCD_SetData ( swap ( cX ) );     // send low nibble
   LCD_PulseEnable();
   output_low ( LCD_RS );
   }
/***entegreterbiyecisi@yahoo.com***/
void LCD_PutCmd ( unsigned int cX )
   {
   // this subroutine works specifically for 4-bit Port A
   LCD_SetData ( swap ( cX ) );     // send high nibble
   LCD_PulseEnable();
   LCD_SetData ( swap ( cX ) );     // send low nibble
   LCD_PulseEnable();
   }
/***entegreterbiyecisi@yahoo.com***/
void LCD_PulseEnable ( void )
   {
   output_high ( LCD_EN );
   delay_us ( 100 );
   output_low ( LCD_EN );
   delay_ms ( 5 );
   }
/***entegreterbiyecisi@yahoo.com***/
void LCD_SetData ( unsigned int cX )
   {
   output_bit ( LCD_D4, cX & 0x01 );
   output_bit ( LCD_D5, cX & 0x02 );
   output_bit ( LCD_D6, cX & 0x04 );
   output_bit ( LCD_D7, cX & 0x08 );
   }
/***entegreterbiyecisi@yahoo.com***/ //lcd son
////////////////////////////////////////////////////////////////////////////
[email]entegreterbiyecisi@yahoo.com[/email]