So-net無料ブログ作成
検索選択
前の10件 | -

JALV2による表示試験 [jalv2_PIC]

mikroCのよる表示を JALV2で置き換えてみました。

位取りの変換ルーチンが動かず、数字は上の桁から下りてきまして、書き換えない所は残ってしまうので

毎回1行クリアを使っています。

位変更のため1/10,1/100をするにはmathルーチンが使えると思っていたら、

16bitしかサポートされていなかったのは、痛かった。

sIMG_0594.jpg

ジタバタしているうちに、レンジ表示とdword割り算の解決法が見つかりました。

上流はまだ解決していません。(変更点は次です)

          var dword divs;
          const byte msg1[] = " M  K  H";
          const byte msg2[] = "  M  K  ";
          const byte msg3[] = "G  M  K ";
         
       if (freq <   99999999) then
          temp = freq;
          lcd_cursor_position(1,0)
          print_string(lcd, msg1)
       elsif (freq <  999999999) then
          divs = 10;
          temp = freq / divs;
          lcd_cursor_position(1,0)
          print_string(lcd, msg2)
       elsif (freq < 4290000000) then
           divs = 100;
           temp = freq / divs;
          lcd_cursor_position(1,0)
          print_string(lcd, msg3)
       end if                ;"12345678"
        lcd_cursor_position(0,0)
        lcd_clear_line(0)
        print_dword_dec(lcd, temp)
 

format.jal


コメント(0) 

JALV2のためのmikroC による変数表示関数 [jalv2_PIC]

こんばんは 文字列表示関数は「const  byte  str1[] = "XXX”」「print_string(lcd, str1)」

で出来るんですが、

少し前から調べていた解釈の範囲では変数列を表示するのに「print_byte_dec()」や「format_byte_dec

「byte」は「word」「byte*3」「dword」等が使えて、

「print」の場合は整数 「format」の場合は 出力デバイス、データ、符号を含む長さ、少数以下を指定できるようです。まだ良く判っていないので、(小数を扱うにはレシプロカルが必須です。)

表示が整数の場合はオートレンジを mkroC で組んでみますと位取りが見やすくなりました。

モード切替で、プリスケーラ、リフレッシュレート等を設定して表示モードに切り換えれば、

使いやすくなります、特に設定値をEEPROMに入れなくても、一番使うモードをデフォルトにしておけば

凝ったプログラムを組まなくてもよいのが助かります。

mikroC の場合は変数表示関数が アンサインを指定していても、マイナスを表示するようです。

また、ただ2倍、1/2にカウントする内容しかないのにほとんどメモリーを使い切ってしまいそうでした。

(実際に作るにはJALV2でないとプログラムが入りきれないでしょう)

void main()
{
    static    char*                msg;
    static    unsigned    long     freq, temp;    // 0...4294967295
    static    unsigned    char    buf[20], cdir;
    // アナログの設定
    //ANSEL    = 0b00000000;    // 使用しない。
    CMCON  = 0b00000111;
  // ポートの設定
    TRISA  = 0b11110000;
    TRISB  = 0b01000111;
    OPTION_REG.F7 = 0;        // PORTBをプルアップする。
    // LCD(液晶モニタ)の初期化
    Lcd_Custom_Config(&PORTA,0,1,2,3,&PORTB,4,5,7);
    Lcd_Custom_Cmd(LCD_CURSOR_OFF);
    Lcd_Custom_Out(1, 1, "FreqCV7");
    Delay_ms(1000);
    Lcd_Custom_Cmd(LCD_CLEAR);
                    freq  = 1; //KARISHUUHASUU      1k   #########
    while (1) {
        // 周波数の測定
        LED = 1;
                if (freq >= 1000000000) {      //4294967295
            cdir = 0;
            } else if (freq < 2) {
        freq = 1;
        cdir = 1;
            }
            if (cdir == 1) {
            freq = freq * 2;     //100k
        } else {
            freq = freq / 2;
            }
    Delay_ms(1000);
        LED = 0;
        //換算
        // プリスケーラの切り替え
      temp = freq;
       if (freq <   99999999) {
           msg =       " M  K  H";
           }
      else if (freq < 999999999) {
                  temp = temp / 10;
           msg =       "  M  K  ";
           //           12345678
           }        //4294967295
      else if (freq < 4290000000 ) {
                  temp = temp / 100;
           msg =       "G  M  K ";
           }
    LongToStr(temp, buf);
        Lcd_Custom_Out(2, 1, msg);
        // 周波数の表示
        Lcd_Custom_Out(1, 1, &buf[3]);
        //
        Delay_ms(10);
    }
}

sIMG_0587.jpg

 

 


コメント(0) 

JALV2はlcd表示が弱い [jalv2_PIC]

こんばんは

JALV2で測定値を表示しようとして、頓挫。

直接8桁書き出す関数やライブラリを見つけることが出来ません。

この部分はmikroCで試して、サンプリングレートとプリスケーラを自動化すればsw関数も要らないと思い、

桁表示だけを下列に出し半自動化してみたら、メモリが99%になってしまった。

JALV2なら50%くらいで済むので、表示関数が使えるとほとんど自動で使えるのではないかとおもいます。

言語の括弧付き変数が良く判らなかったのですが、これは計算値を求めリターンがあるので、

ファンクション関数であるのが判りました。

tmr1のプリスケーラ(8倍)は工夫をすればクロック読み出しも出来るので 、少しなら精度も上げられます。

仮に80MHzの数値を与えて、表示させてみました。

もっと低い所を測るにはレシプロカル測定法を使わねば成りません。

sIMG_0579.jpg

 


コメント(0) 

ファンクションの設定や表示は後回しにして [jalv2_PIC]

ファンクション名定数で与え、測定計算の部分だけプログラムを書き換えました。

一応エラーはありませんが、目的のデータが得られたかは、次の表示関数を実装してからでないと分かりません。

-- --------------------------------------------------------------------------
--
-- Title: Test program for lcd_hd44780_4.jal (basic / interface test)
-- Author: Eur Van Andel, Copyright (c) 2008-2010, all rights reserved.
-- Adapted-by: Rob Hamerling, Joep Suijs
-- Compiler: >=2.4m
-- Revision: $Revision: 2811 $
--
-- This file is part of jallib  (http://jallib.googlecode.com)
-- Released under the BSD license (http://www.opensource.org/licenses/bsd-license.php)
--
-- Description:
-- This sample shows how to setup an LCD and writes
-- "Hello World" to the first line, using a string and the print library.
-- A counter is printed to show the running forever loop.
-- --
-- This file defines a test for JALLIB testing, using a test-board
--  defined by a BOARD file .
--
-- Sources:
--
-- Notes:
-- setup: an hd44780 compatible display, used in 4-bit mode.
--
-- --------------------------------------------------------------------------
--
-- This file has been generated from:
--     * board: board_16f648a_js.jal
--     * test : test_lcd_hd44780_4bit.jal
--
--
-- LCD
-- 1    Vss     2 Vdd
-- 3    VO      4 RS
-- 5    R/W(G) 6 E
-- 7    D0      8 D1
-- 9    D2      10 D3
-- 11 D4      12 D5
-- 13 D6      14 D7
-- 15 BLA     16 BLK

-- 16F628A
-- 1 RA2 LCD_5              18 RA1 LCD_6
-- 2 RA3 LCD_4              17 RA0 LCD_7
-- 3 RA4 SWI4              16 RA7 OSC1 XTal IN
-- 4 RA5 MCLR ICSP Vpp 15 RA6 OSC2 XTal OUT
-- 5 Vss ICSP Vss       14 Vdd ICSP Vdd
-- 6 RB0 SWI1              13 RB7 LCD_EN ICSP PGD
-- 7 RB1 SWI2              12 RB6 T1CK_IN ICSP PGC
-- 8 RB2 SWI3              11 RB5 uPB1507GV SEL
-- 9 RB3 LED              10 RB4 LCD_RS

include constants_jallib

if false then;
-- lcd_command       
          lcd'put(byte in data)
          lcd_cursor_position(1, 1)
          lcd_clear_screen()
          lcd_cursor_blink_display(0, 0, 1)
          lcd_home()
          lcd_clear_line(1)
          lcd_write_char(line1[1])
          lcd_cursor_position(0,0)
          print_string(lcd, str1)
          const byte  DAY_OF_WEEK[]            = "SuMoTuWeThFrSa"             -- weekday abbreviations
          lcd = DAY_OF_WEEK[weekday * 2]                   -- day of week
          const byte  ALARM_SIGN                = 0b0101_1100                     -- Yen(?)
          lcd = ALARM_SIGN
end if
-- ---------------------------------------------------
;@jallib section chipdef
-- chip setup
include 16f628a;
include math;

--
-- This program assumes a 20 MHz resonator or crystal
-- is connected to pins OSC1 and OSC2.
pragma target OSC HS                   -- HS crystal or resonator
pragma target clock 20_000_000;      -- oscillator frequency
pragma target WDT  disabled;
pragma target LVP  disabled;

;@jallib section lcd_hd44780_4
-- ---------------------------------------------------
-- LCD IO definition
alias        lcd_en         is pin_B7;         -- data trigger
alias        lcd_rs         is pin_B4;         -- command/data select.
pin_B7_direction         = output;
pin_B4_direction         = output;

alias        lcd_d4         is pin_A3;
alias        lcd_d5         is pin_A2;
alias        lcd_d6         is pin_A1;
alias        lcd_d7         is pin_A0;

pin_A3_direction         = output;
pin_A2_direction         = output;
pin_A1_direction         = output;
pin_A0_direction         = output;
-- ---------------------------------------------------
-- ---------------------------------------------------
const byte LCD_ROWS        = 2;                            -- 2 lines
const byte LCD_CHARS     = 8;                            -- 8 chars per line
-- ---------------------------------------------------
-- LED IO definition
alias        led         is pin_B3;
pin_B3_direction          =  output;       -- blinking LED
-- uPB1507GV SEL
alias        exps         is pin_B5;
pin_B5_direction          =  output;       -- EXT PS sel

-- sw io definition
alias        swi1         is pin_B0;
pin_B0_direction          =  input;       -- sw1 in
alias        swi2         is pin_B1;
pin_B1_direction          =  input;       -- sw2 in
alias        swi3         is pin_B2;
pin_B2_direction          =  input;       -- sw3 in
alias        swi4         is pin_A4;
pin_A4_direction          =  input;       -- sw4 in
-- ---------------------------------------------------
;@jallib section led

include delay;
--include lcd_hd44780_common;
include lcd_hd44780_4;                     -- LCD library with 4 data lines
lcd_init();                                     -- initialize LCD
include print;                                 -- formatted output library

-- ---------------------------------------------------

;var bit swi1,swi2,swi3,swi4;

swi1 = 0;
swi2 = 0;
swi3 = 0;
swi4 = 0;


const  byte   gatec_time01 =      1
const  byte   gatec_time06 =      6
const  byte   gatec_time10 =     10
var          word          time_count;
var  dword freq;
var  byte  prscler     = 8; karisettei 1/8
var  bit   ifon         = 0; karisettei -445 off
var  dword freq_meas;
var  byte  gate_timer = 1; karisettei 0.1Sec
var  bit   fricfunc     = 0; karisettei Hz
-- ----------------------------------------------------------
        procedure gatec_time is
          pragma interrupt
              PIR1_TMR2IF = 0;
              time_count = time_count - 1;
              if (time_count == 0) then
                  t1con_tmr1on = 0;            -- gate close
                  t2con_tmr2on = 0;            -- timer2 to stop
              end if     
        end procedure
       
-- ----------------------------------------------------------
; kukannnaishuuhasuukaunnto
;var dword freq_meas(byte gatec_time);
;gate_timer = gatec_time01; ####
;freq_meas = freq_meas * 10;
freq_meas = (freq_meas / gate_timer) * 10;

;          var volatile dword freq;
          ;timer1 is set
          pir1_tmr1if = 0;
          tmr1l = 0;
          tmr1h = 0;
          ;timer2 is set
          pir1_tmr2if = 0;

          case gate_timer of
          gatec_time10:
                     block
                     time_count = 1221;              ; 312500=1/((1/20000000) * 4 * 16)
                     tmr2 = 0x4C;                      ; 0x4c=256-(312500-(256*1220))
                     end block
          gatec_time06:
                     block
                     time_count = 733;             ; 31250=0.6/((1/20000000) * 4 * 16)
                     tmr2 = 0x94;                      ; 148 0x94=256-(187500-(256*732))
                     end block
          gatec_time01:
                     block
                     time_count = 123;              ; 31250=0.1/((1/20000000) * 4 * 16)
                     tmr2 = 0xee;                      ; 0xee=256-(31250-(256*122))
                     end block
          end case
          ;
          freq = 0;
          ; enable to interrupt
          intcon_peie = 1;
          intcon_gie = 1;
          ; start
          t2con_tmr2on = 1;            ;timet start
          ;          delay
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          asm          nop;
          ;
          t1con_tmr1on = 1;            ;open gate
         
          ; mes
          while (T2CON_TMR2ON != 0) loop
                     if (PIR1_TMR1IF == 1) then
                                PIR1_TMR1IF = 0; jyunnkann
                                freq = freq + 1; ketaagari
                     end if
          end loop

          if (PIR1_TMR1IF == 1) then
                     PIR1_TMR1IF = 0; jyunnkann
                     freq = freq + 1; ketaagari
          end if

          ;Conversion
          freq = freq * 65536;
;          freq = freq + (TMR1H * 256) + TMR1L;
          freq = freq + TMR1;
          ;
;            return (freq);
-- ----------------------------------------------------------
block
--       static                     char*                                             msg;
          var volatile          dword          freq, temp;            ; 0...4294967295
          var volatile          byte          buf[20], msg[], prescaler, gatetime;
          ; compa set
          CMCON    = 0b0000_0111;          -- disable comparator
          OPTION_REG_NRBPU = 0;
          enable_digital_io();

          ;ansel  = 0b00000000;          ;not use
          ; port set
          trisa    = 0b11100000;
          trisb    = 0b01001111;
          ; timer2 is set
          pie1_tmr2ie = 1;
          pir1_tmr2if = 0;
          t2con_toutps = 0;
          t2con_tmr2on = 0;
          t2con_t2ckps = 3;
          tmr2 = 0;
          ; timer1 is set
          pie1_tmr1ie = 0;
          pir1_tmr1if = 0;
--          t1con_t1run = 0;  16f88 opnly
          t1con_t1ckps = 0;
          t1con_t1oscen = 0;
          T1CON_NT1SYNC = 1;
          t1con_tmr1cs = 1;
          t1con_tmr1on = 0;
          tmr1 = 0;
          ;variables is init
          prscler = 1;
          gatetime = gatec_time10;

         
          Delay_1ms(1000);
       
          lcd_clear_screen()
          ;
-- --- generate LCD screen activity ---------

var byte counter = 0

          forever loop
         
         

;          while (1) loop
                     ; friq_mes
                     LED = 1;
                     freq_meas = freq_meas * gate_timer / 10; #### rifureshulate
;                     freq = freq_meas(gate_timer);
                     freq = freq_meas;
                     LED = 0;
                     ;Conversion
                     freq = freq * prescaler * gateTime;
                     
                     ; prscler_selct
                     if (prscler == 1) then
                                T1CON_T1CKPS = 0;
                                prescaler = 1;
                                exps = 0;
;                                msg = "1/1 ";
                     end if
                     if (prscler == 8) then
                                T1CON_T1CKPS = 3;
                                prescaler = 8;
                                exps = 0;
;                                msg = "1/8 ";
                     end if
                     if (prscler == 64) then
                                T1CON_T1CKPS = 0;
                                prescaler = 64;
                                exps = 1;
;                                msg = "1/64";
                     end if
;                     Lcd_Out(2, 1, msg);                 ##

;                      print_string(lcd, msg)
                     ; gatec_time _serect
                     if (gatec_time10 == gatetime) then
;                                gateTime = gatec_time10;
;                                msg = "1sec   ";
                     end if
                     if (gatec_time06 == gatetime) then
;                                 gateTime = gatec_time06;
;                                msg = "0.6sec ";
                     end if
                     if (gatec_time01 == gatetime) then
;                                 gateTime = gatec_time01;
;                                msg = "0.1sec ";
                     end if
                     
;                     Lcd_Out(2, 5, msg);                 ##
                     ; -if
                     if (ifon == 1) then
                                freq = freq - 455000;
;                                msg = "-455k";
                     else
;                                msg = "     ";
                     end if
                     
;                     Lcd_Out(2, 12, msg);                 ##
                     ; disp range select
                     if (fricfunc == 0) then
;                                LongToStr(freq, buf);
;                                msg = "Hz ";
                     else
                                temp = freq / 1000;
                                if ((freq - (temp * 1000)) > 500) then
                                          temp = temp + 1;
;                                 LongToStr(temp, buf);
;                                msg = "kHz";
                                end if
                     end if
                     
;                     Lcd_Out(1, 9, msg);                      ##
                     ; friq_disp
;                     Lcd_Out(1, 1, &buf[3]);                 ##
                     ;
                     Delay_1ms(500);
     end loop
end block
-- ----------------------------------------------------------

Compilation started at :2012/04/24 17:39:37
jal 2.4o (compiled May  8 2011)
Compiler CommandLine:  C:\JALPack\compiler\jalv2.exe "D:\_users\_jalvs\n8\5friq_lcd.jal" -s "C:\JALPack\lib" -no-variable-reuse 

Errors :0       Warnings :0
Code   :870/2048    Data:74/208  Hardware Stack : 3/8  Software Stack :80
 


コメント(0) 

C言語をjalv2に書き換え1個のエラーが出ます [jalv2_PIC]

こんにちは

C言語をjalv2に書き換え1個のエラーが出ます、

しかし基本的な間違いを残したままで、直すとかえってエラーだらけになります。

最後の所にLCD表示関数をまとめています。

-- --------------------------------------------------------------------------
-- "Hellowld!" +    1byte_hex * blinking LED + cursor
-- Title: Test program for lcd_hd44780_4.jal (basic / interface test)
-- Author: Eur Van Andel, Copyright (c) 2008-2010, all rights reserved.
-- Adapted-by: Rob Hamerling, Joep Suijs
-- Compiler: >=2.4m
-- Revision: $Revision: 2811 $
--
-- This file is part of jallib  (http://jallib.googlecode.com)
-- Released under the BSD license (http://www.opensource.org/licenses/bsd-license.php)
--
-- Description:
-- This sample shows how to setup an LCD and writes
-- "Hello World" to the first line, using a string and the print library.
-- A counter is printed to show the running forever loop.
-- --
-- This file defines a test for JALLIB testing, using a test-board
--  defined by a BOARD file .
--
-- Sources:
--
-- Notes:
-- setup: an hd44780 compatible display, used in 4-bit mode.
--
-- --------------------------------------------------------------------------
--
-- This file has been generated from:
--     * board: board_16f648a_js.jal
--     * test : test_lcd_hd44780_4bit.jal
--
--
-- LCD
-- 1    Vss     2 Vdd
-- 3    VO      4 RS
-- 5    R/W(G) 6 E
-- 7    D0      8 D1
-- 9    D2      10 D3
-- 11 D4      12 D5
-- 13 D6      14 D7
-- 15 BLA     16 BLK

-- 16F628A
-- 1 RA2 LCD_5              18 RA1 LCD_6
-- 2 RA3 LCD_4              17 RA0 LCD_7
-- 3 RA4 SWI4              16 RA7 OSC1 XTal IN
-- 4 RA5 MCLR ICSP Vpp 15 RA6 OSC2 XTal OUT
-- 5 Vss ICSP Vss       14 Vdd ICSP Vdd
-- 6 RB0 SWI1              13 RB7 LCD_EN ICSP PGD
-- 7 RB1 SWI2              12 RB6 T1CK_IN ICSP PGC
-- 8 RB2 SWI3              11 RB5 uPB1507GV SEL
-- 9 RB3 LED              10 RB4 LCD_RS
-- ---------------------------------------------------
;@jallib section chipdef
-- chip setup
include 16f628a;

--
-- This program assumes a 20 MHz resonator or crystal
-- is connected to pins OSC1 and OSC2.
pragma target OSC HS                   -- HS crystal or resonator
pragma target clock 20_000_000;      -- oscillator frequency
pragma target WDT  disabled;
pragma target LVP  disabled;

;@jallib section lcd_hd44780_4
-- ---------------------------------------------------
-- LCD IO definition
alias        lcd_en         is pin_B7;         -- data trigger
alias        lcd_rs         is pin_B4;         -- command/data select.
pin_B7_direction         = output;
pin_B4_direction         = output;

alias        lcd_d4         is pin_A3;
alias        lcd_d5         is pin_A2;
alias        lcd_d6         is pin_A1;
alias        lcd_d7         is pin_A0;

pin_A3_direction         = output;
pin_A2_direction         = output;
pin_A1_direction         = output;
pin_A0_direction         = output;
-- ---------------------------------------------------
-- ---------------------------------------------------
const byte LCD_ROWS        = 2;                            -- 2 lines
const byte LCD_CHARS     = 8;                            -- 8 chars per line
-- ---------------------------------------------------
-- LED IO definition
alias        led         is pin_B3;
pin_B3_direction          =  output;       -- blinking LED
-- uPB1507GV SEL
alias        exps         is pin_B5;
pin_B5_direction          =  output;       -- EXT PS sel

-- sw io definition
alias        swi1         is pin_B0;
pin_B0_direction          =  input;       -- sw1 in
alias        swi2         is pin_B1;
pin_B1_direction          =  input;       -- sw2 in
alias        swi3         is pin_B2;
pin_B2_direction          =  input;       -- sw3 in
alias        swi4         is pin_A4;
pin_A4_direction          =  input;       -- sw4 in
-- ---------------------------------------------------
;@jallib section led

include delay;
--include lcd_hd44780_common;
include lcd_hd44780_4;                     -- LCD library with 4 data lines
lcd_init();                                     -- initialize LCD
include print;                                 -- formatted output library


;var bit swi1,swi2,swi3,swi4;

swi1 = 0;
swi2 = 0;
swi3 = 0;
swi4 = 0;

--#define                      gatec_time01 is        10
--#define                      gatec_time06 is        1/6
--#define                      gatec_time10 is        1
const  byte   gatec_time01 =     10
const  byte   gatec_time06 =      1/6
const  byte   gatec_time10 =      1
var          word          time_count;
var  dword freq;
--var  byte gatec_time;

-- ----------------------------------------------------------
        procedure gatec_time is
          pragma interrupt
              PIR1_TMR2IF = 0;
              time_count = time_count - 1;
              if (time_count == 0) then
                  t1con_tmr1on = 0;            -- gate close
                  t2con_tmr2on = 0;            -- timer2 to stop
              end if      
        end procedure
       
-- ----------------------------------------------------------
--function friq_mes (DWORD IN n) RETURN byte IS
var dword freq_meas(byte gatec_time);
;var dword freq_meas[byte gatec_time];
          block
          var volatile dword freq;
          ;timer1 is set
          pir1_tmr1if = 0;
          tmr1l = 0;
          tmr1h = 0;
          ;timer2 is set
          pir1_tmr2if = 0;

          case gatec_time of
          gatec_time10:
                     time_count = 1221;
                     tmr2 = 0x4c;                      ; 312500=1/((1/20000000) * 4 * 16)
                                                          ; 0x4c=256-(312500-(256*1220))
;            gatec_time06:
;                      time_count = 733;
;                      tmr2 = 0x94;        ; 31250=0.6/((1/20000000) * 4 * 16)
;                                                          ; 148 0x94=256-(187500-(256*732))
          gatec_time01:
                     time_count = 123;
                     tmr2 = 0xee;                      ; 31250=0.1/((1/20000000) * 4 * 16)
                                                          ; 0xee=256-(31250-(256*122))
          end case
          ;
          freq = 0;
          ; enable to interrupt
          intcon.peie = 1;
          intcon.gie = 1;
          ; start
          t2con.tmr2on = 1;            ;timet start
          ;          delay
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          asm         nop;
          ;
          t1con_tmr1on = 1;            ;open gate
          ; mes

          while (T2CON_TMR2ON != 0) loop
                     if (PIR1_TMR1IF == 1) then
                                PIR1_TMR1IF = 0;
                                freq = freq + 1;
                     end if
          end loop

          if (PIR1.TMR1IF == 1) then
                     PIR1_TMR1IF = 0;
                     freq = freq + 1;
          end if

          ;Conversion
          freq = freq * 65536;
          freq = freq + (TMR1H * 256) + TMR1L;
          ;
;            return (freq);
             --[ exit loop ]
          end block
--end function        
-- ----------------------------------------------------------
--        static        char*                                msg;
          forever loop

          var volatile        char*                                          msg;
          var volatile         dword          freq, temp;            ; 0...4294967295
          var volatile         byte          buf[20], prescaler, gatetime;
    CMCON  = 0b0000_0111;          -- disable comparator
    OPTION_REG_NRBPU = 0;
    enable_digital_io();

          ; compa set
          ;ansel  = 0b00000000;         ;not use
          ; port set
          trisa    = 0b11100000;
          trisb    = 0b01001111;
          ;option_reg_nrbpu = 0;                     ; portb is pullup
          ; timer2 is set
          pie1_tmr2ie = 1;
          pir1_tmr2if = 0;
          t2con_toutps0 = 0;
          t2con_toutps1 = 0;
          t2con_toutps2 = 0;
          t2con_toutps3 = 0;
          t2con_tmr2on = 0;
          t2con_t2ckps0 = 1;
          t2con_t2ckps1 = 1;
          tmr2 = 0;
          ; timer1 is set
          pie1_tmr1ie = 0;
          pir1_tmr1if = 0;
          t1con_t1run = 0;
          t1con_t1ckps0 = 0;
          t1con_t1ckps1 = 0;
          t1con_t1oscen = 0;
          t1con_not_t1sync = 1;
          t1con_tmr1cs = 1;
          t1con_tmr1on = 0;
;            tmr1l = 0;
;            tmr1h = 0;
            tmr1 = 0;
          ;variables is init
          prs = 1;
          gatetime = gatec_time10;

;            lcd_init
;            Lcd_port_set
    LCD_Init();
          Lcd_Cmd(_LCD_CURSOR_OFF);
          Lcd_Out(1, 1, "FreqCounter V7");
         
          Delay_ms(1000);
          Lcd_Cmd(_LCD_CLEAR);
         
          ;
         
          while (1) loop
                     ; friq_mes
                     LED = 1;
                     freq = FreqMeasurement(gateTime);
;                      freq = FreqMeasurement[gateTime];
                     LED = 0;
                     ;Conversion
                     freq = freq * prescaler * gateTime;
                     ; prs_selct
                     if (sw1 == 1) then
                                T1CON_T1CKPS0 = 0;
                                T1CON_T1CKPS1 = 0;
                                prescaler = 1;
                                msg = "1/1 ";
                      else
                                T1CON_1CKPS0 = 1;
                                T1CON_1CKPS1 = 1;
                                prescaler = 8;
                                msg = "1/8 ";
                     end if
                     
                     Lcd_Out(2, 1, msg);
                     ; gatec_time _serect
                     if (sw2 == 1) then
                                gateTime = gatec_time10;
                                msg = "1sec   ";
                      else
                                gateTime = gatec_time01;
                                msg = "0.1sec ";
                     end if
                     
                     Lcd_Out(2, 5, msg);
                     ; -if
                     if (sw3 == 0) then
                                freq -= 455000;
                                msg = "-455k";
                      else
                                msg = "     ";
                     end if
                     
                     Lcd_Out(2, 12, msg);
                     ; disp range select
                     if (sw4 == 1) then
                                LongToStr(freq, buf);
                                msg = "Hz ";
                      else
                                temp = freq / 1000;
                                if ((freq - (temp * 1000)) > 500) then
                                          temp = temp + 1;
                                end if
                                LongToStr(temp, buf);
                                msg = "kHz";
                     end if
                     Lcd_Out(1, 9, msg);
                     ; friq_disp
                     Lcd_Out(1, 1, &buf[3]);
                     ;
                     Delay_ms(500);
          end loop
-- lcd_command        
          __lcd_write(5)
          _lcd_write_data(5)
          _lcd_write_command(5)
          _lcd_line2index(1) return
--          freq =
          lcd'put(byte in data)
          lcd_cursor_position(1, 1)
          lcd_clear_screen()
          lcd_cursor_blink_display(0, 0, 1)
          lcd_home()
          lcd_clear_line(1)
          lcd_write_char(line1[1])
          lcd_cursor_position(0,0)
          print_string(lcd, str1)
          const byte  DAY_OF_WEEK[]            = "SuMoTuWeThFrSa"             -- weekday abbreviations
          lcd = DAY_OF_WEEK[weekday * 2]                  -- day of week
         
          const byte  ALARM_SIGN                = 0b0101_1100                     -- Yen(?)
          lcd = ALARM_SIGN
--          
          end loop
-- ----------------------------------------------------------

Compilation started at :2012/04/22 17:37:47
jal 2.4o (compiled May  8 2011)
[Error] (5friq_lcd.jal) [Line 143]  unexpected token: (
Compiler CommandLine:  C:\JALPack\compiler\jalv2.exe "D:\_users\_jalvs\n8\5friq_lcd.jal" -s "C:\JALPack\lib" -no-variable-reuse 

Errors :1       Warnings :0
コメント(0) 

sw入力のテストをしました [jalv2_PIC]

jalv2の場合 条件判断を複数ロジカル判断によるよりも、単段ロジカル判断にして、

加減算は先に済ませてから規定値内に引き戻す方法で、20バイト位少なくなることが判りました。

下記のソース部分は、液晶駆動の一部とsw入力をデチャッタ処理して押したボタンの数を勘定できる様にまりました。

PIC16fの一部のデバイスはAポートがオープンコレクタになったのがあって、GND側に繋いだLEDが点灯せず、

悩んだことがあります。

電源側を使うのも簡単ですが、ノイズ環境など考えるとGND側に統一するのが良さそうです。

PIC16F628Aの場合ですとADコンがありませんがコンパレータがデフォルトなので、

これをデジタルに設定し、BポートのプルUPを活かしてsw入力の抵抗を省き、リファレンス電圧を禁止にしますと

結構な数の入出力が使えて、周波数カウンタ程度なら組むことが出来そうです。

16f648aを使えばレシプロカルカウンタの出来るかもしれません。

レシプロカルカウンタの原理はいろいろあるようですが、間違った理論が載っていたのを見たことがあります。

やはり自分で理論的裏付けを取って、使うに越したことはないでしょう。

-- --------------------------------------------------------------------------
--
-- This file has been generated from:
--     * board: board_16f648a_js.jal
--     * test : test_lcd_hd44780_4bit.jal
--
--
-- LCD
-- 1    Vss     2 Vdd
-- 3    VO      4 RS
-- 5    R/W(G) 6 E
-- 7    D0      8 D1
-- 9    D2      10 D3
-- 11 D4      12 D5
-- 13 D6      14 D7
-- 15 BLA     16 BLK

-- 16F628A
-- 1 RA2 LCD_5              18 RA1 LCD_6
-- 2 RA3 LCD_4              17 RA0 LCD_7
-- 3 RA4 SW4              16 RA7 OSC1 XTal IN
-- 4 RA5 MCLR ICSP Vpp 15 RA6 OSC2 XTal OUT
-- 5 Vss ICSP Vss       14 Vdd ICSP Vdd
-- 6 RB0 SW1              13 RB7 LCD_EN ICSP PGD
-- 7 RB1 SW2              12 RB6 T1CK_IN ICSP PGC
-- 8 RB2 SW3              11 RB5 uPB1507GV SEL
-- 9 RB3 LED              10 RB4 LCD_RS
-- ---------------------------------------------------
;@jallib section chipdef
-- chip setup
include 16f628a;

--
-- This program assumes a 20 MHz resonator or crystal
-- is connected to pins OSC1 and OSC2.
pragma target OSC HS                   -- HS crystal or resonator
pragma target clock 20_000_000;      -- oscillator frequency
pragma target WDT  disabled;
pragma target LVP  disabled;

;@jallib section lcd_hd44780_4
-- ---------------------------------------------------
-- LCD IO definition
alias        lcd_en         is pin_B7;         -- data trigger
alias        lcd_rs         is pin_B4;         -- command/data select.
pin_B7_direction         = output;
pin_B4_direction         = output;

alias        lcd_d4         is pin_A3;
alias        lcd_d5         is pin_A2;
alias        lcd_d6         is pin_A1;
alias        lcd_d7         is pin_A0;

pin_A3_direction         = output;
pin_A2_direction         = output;
pin_A1_direction         = output;
pin_A0_direction         = output;
-- ---------------------------------------------------
-- ---------------------------------------------------
const byte LCD_ROWS        = 2;                            -- 2 lines
const byte LCD_CHARS     = 8;                            -- 8 chars per line
-- ---------------------------------------------------
-- LED IO definition
alias        led         is pin_B3;
pin_B3_direction          =  output;       -- blinking LED
-- uPB1507GV SEL
alias        exps         is pin_B5;
pin_B5_direction          =  output;       -- EXT PS sel

-- sw io definition
alias        sw1         is pin_B0;
pin_B0_direction          =  input;       -- sw1 in
alias        sw2         is pin_B1;
pin_B1_direction          =  input;       -- sw2 in
alias        sw3         is pin_B2;
pin_B2_direction          =  input;       -- sw3 in
alias        sw4         is pin_A4;
pin_A4_direction          =  input;       -- sw4 in
-- ---------------------------------------------------
;@jallib section led

include delay;
--include lcd_hd44780_common;
    CMCON  = 0b0000_0111;          -- disable comparator
    OPTION_REG_NRBPU = 0;
    enable_digital_io();
include lcd_hd44780_4;                     -- LCD library with 4 data lines
include print;                                 -- formatted output library
lcd_init();                                     -- initialize LCD

for 4 loop;                                     -- blink LED 4 times to indicate startup
    LED = on;
    delay_100ms(2);
    LED = off;
    delay_100ms(2);
end loop;

const byte str1[] = "FriqC V7";     -- define strings
lcd_cursor_position(0,0);                 -- to 1st line, 1st char
print_string(lcd, str1);                  -- show hello world!
delay_100ms(10);
lcd_clear_line(1);

var bit sf1=0,sf2,sf3,sf4;
var byte sn1,cp1;

sn1 = 0;
cp1 = 0;

forever loop                                    -- loop forever

    if (sw1 != 1)  then
       if (sf1 == 0) then
           sn1 = sn1 + 1;
           delay_1ms(10);
         if sn1 > 3 then
            sn1 = 3;
               sf1 = 1;
               led = 1;
               cp1 = cp1 + 1;
               if cp1 > 7 then
                   cp1 = 0;
               end if
         end if
       end if
   end if
   if (sw1 == 1) then
      if (sf1 == 1) then
           sn1 = sn1 - 1;
           delay_1ms(10);
         if sn1 <= 0 then
            sn1 = 0;
               sf1 = 0;
               led = 0;
         end if
      end if
   end if
      lcd_cursor_position(1,0);
      print_byte_hex(lcd, sn1);
      lcd_cursor_position(1,3);
      print_byte_hex(lcd, cp1);
     
end loop
 


コメント(0) 

ほぼ思い通りに仕上がったが [jalv2_PIC]

こんにちは

ほぼ思い通りに仕上がったんですが、LCDコントロールは結構無理が有って、

アンダーカーソルを使うのは見えにくい。

1個のボタンで、右に流して行き、各設定をもう一個のボタンで切り換えようと思ったんですが、

プリスケーラ 1/1,1/8,1/64 サンプリングタイム1/10、6/10,1/1秒

周波数レンジ GHzMHz、KHz、mHz、uHz  を切り換えたいと思っています。

(意味のない設定もありますが)他には表示の下にアンダーラインを出して位取りにも当てようと思ったのですが

アンダーラインやカーシル(ブリンクしかないみたい)は同時に1カ所すかでないので時分割でチラチラとしかでません。

ボタン(チャタリング防止)は30msにしたはずですが1秒くらいかかっています。

プログラムループのせいか、(まだ計っていません)クロック周波数のせいなのかはハッキリしません、

上の桁のアンダーカーソルはまだ制御せず、下のを時分割で共用しています 。

00はボタンを離したカウントで03に成ると、0から7の間をカラムが右に動きます。

tmr1とtmr2を使うこの方式ではプリスケーラに貯まった分が読み出せれば精度はよくなるんですが、

(TMR1CS)を使ってtmr1の加算を確認するのも結構面倒ですが、AN592の様に抵抗を使わない文絡かも知れません。

 

sIMG_0570.jpg

 


コメント(0) 

カーソルは自由に動かすことが出来ました。 [jalv2_PIC]

こんにちは

カーソルは 

アンダーライン、アンダーライン付ブリンキング アンダーライン無しブリンキング、表示消し に対応できて

順次送ることが出来ます、(文字のある場所にも適用できます)

しかしカーソルは1カ所しか表示できないので、周波数計測値の位取りに、CGRAM領域にアンダーカーソルを書き込むべく、

lcd_hd44780_common.jal に一部の追加をしました。

-- ----------------------------------------------------------------------------
-- Sends data LCD_SET_CGRAM_data byte in <value> to LCD
-- ----------------------------------------------------------------------------
procedure lcd_write_CGRAM_data(byte in line,byte in LCD_ROWS,byte in value) is
/line = _lcd_line2index(line)
--LCD_SET_CGRAM_ADDRESS--(line)
_lcd_write_command( lcd_set_ddram_address | lcd_pos )
lcd_rs = high
   __lcd_write(value)                           -- write byte
lcd_rs = low
end procedure

これを  1cursor_16f628a_lcd_hd44780_4bit_command.jal カーソル試験ルーチンから呼び出しますと、

   lcd_write_CGRAM_data(0,2,0x0E)
   delay_100ms(5)

最後にカーソルを移動した所に カタカナのミの様な字(横

4本線)が表示される様になりました。

なにか書き込んではいるのですが、CGRAMのアドレスやデータなどがまだ不完全なようです。

sIMG_0568.jpg

 

 

 

 

 

 

 

 


コメント(0) 

今度はjalv2のLCDライブラリが見つかったので試してみました。 [jalv2_PIC]

mikoroCやmikroC_proは取っつきは良いのですが、LCD関数の内容に不明な点が多く、

(ただ無知なだけかも知れません)

jalv2で文字表示HEX表示、アンダーラインを2行目(1と表す)5文字目に出し前後2桁動かしながら、

ベタカーソル、ブリンキングをやってみました。

アンダーラインやカーソルは全文字面で1カ所しか表示できず、位置指定と左右移動で操作できます。

mikroCではどの様に操作すればいいのか、返事もなかった(mikroC から mikroC_pro へのインポート不具合)はこの方向で解決せねばならないようです。

mikroC  に有ったbutton関数は組み込まれている様なので内容が判らず、

これも何らかのプログラムを作り必要があり、タイマーコントロールカウント処理、計算処理、

とまだまだ前途多難です。

(2行目3桁目のブリンキング5桁目薄いアンダーライン7桁目のアンダーライン、ブリンキングが始まっていません)

sIMG_0565.jpg

 


コメント(0) 

一度原点に戻って mikroC で組んでみました。 [jalv2_PIC]

JALV2ではLCD関連コマンドが違っており、コメントアウトが多すぎて何をやっているか判らなくなってしまいました。

しかし元のソースはmikroCを使って16F88で組まれており、手持ちがありません。

現在入手できるMIKROC_PROではミグレイションに従って書き換えてもコンパイルでエラーになり、進展できない。

しかしひょんな事からmikroC_8.2が入手できたので、コンパイルすると出来てしまった。

これをMIKROC_PROでインポートして少しの修正をしてもやはりエラーになってしまう。

この点はメーカーさんに質問中ですが、mikroCを使って次の変更をして16F628Aの20MHzをコンパイルすると、動作するかと思ったのですが、やはり動作しませんでした。

16F88なら動作するのでしょうか?

    // アナログの設定
    CMCON   = 0b00000111;
    //ANSEL    = 0b00000000;    // 使用しない。                 //
    OPTION_REG.F7 = 0;        // PORTBをプルアップする。

    //T1CON.T1RUN = 0;

その後 勘違いと思われる点を修正し 16f628で lcd表示(0)まで確認できました。

(カウントしているかはまだ判りません)

jalv2でコンパイルするとPickit2は必ず書き込みを失敗し、mikrocでは勝手に書き込んでくれます。

ここが少し変ですね。

sIMG_0550.jpg



//**********************************************************************
// LCD
// 1  Vss    2 Vdd
// 3  VO     4 RS
// 5  R/W(G) 6 E
// 7  D0     8 D1
// 9  D2     10 D3
// 11 D4     12 D5
// 13 D6     14 D7
// 15 BLA    16 BLK

// 16F628A
// 1 RA2 LCD_5         18 RA1 LCD_6
// 2 RA3 LCD_4         17 RA0 LCD_7
// 3 RA4 LED           16 RA7 OSC1 XTal IN
// 4 RA5 MCLR ICSP Vpp 15 RA6 OSC2 XTal OUT
// 5 Vss ICSP Vss      14 Vdd ICSP Vdd
// 6 RB0 SW1           13 RB7 LCD_EN ICSP PGD
// 7 RB1 SW2           12 RB6 T1CK_IN ICSP PGC
// 8 RB2 sw3           11 RB5 PSC_sel
// 9 RB3 sw4           10 RB4 LCD_RS


#define     sw1      PORTB.F0
#define     sw2      PORTB.F1
#define     sw3      PORTB.F2
#define     sw4      PORTB.F3
//#define      rs    PORTB.F4
//#define      e     PORTB.F7
//#define      PSC_SEL     PORTB.F5

#define     LED      PORTA.F4

#define     GATETIME_100MSEC  10
#define     GATETIME_1SEC     1

//**********************************************************************

static   unsigned int   MeasurementCnt;

void  interrupt()
{
   PIR1.TMR2IF = 0;
   //
   MeasurementCnt--;
   if (MeasurementCnt == 0) {
      T1CON.TMR1ON = 0; // ゲートを閉める。
      T2CON.TMR2ON = 0; // TIMER2を停止する。
   }
}

//**********************************************************************

unsigned long  FreqMeasurement(unsigned char gateTime)
{
   static   unsigned long  freq;
   // TIMER1の設定
   PIR1.TMR1IF = 0;
   TMR1L = 0;
   TMR1H = 0;
   // TIMER2の設定
   PIR1.TMR2IF = 0;
   switch (gateTime) {
   case GATETIME_1SEC:
      MeasurementCnt = 1221;
      TMR2 = 0x4C;      // 312500=1/((1/20000000) * 4 * 16)
                     // 0x4C=256-(312500-(256*1220))
      break;
   case GATETIME_100MSEC:
      MeasurementCnt = 123;
      TMR2 = 0xEE;      // 31250=0.1/((1/20000000) * 4 * 16)
                     // 0xEE=256-(31250-(256*122))
      break;
   }
   //
   freq = 0;
   // 割り込みを許可する。
   INTCON.PEIE = 1;
   INTCON.GIE = 1;
   // 開始
   T2CON.TMR2ON = 1; //タイマを開始する。
   // Delay
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   asm   nop;
   //
   T1CON.TMR1ON = 1; //ゲートを開ける。
   // 測定
   while (T2CON.TMR2ON != 0) {
      if (PIR1.TMR1IF == 1) {
         PIR1.TMR1IF = 0;
         freq++;
      }
   }
   if (PIR1.TMR1IF == 1) {
      PIR1.TMR1IF = 0;
      freq++;
   }
   //換算
   freq = freq * 65536;
   freq = freq + ((unsigned)TMR1H * 256) + (unsigned)TMR1L;
   //
   return (freq);
}

//**********************************************************************

void main()
{
   static   char*          msg;
   static   unsigned long  freq, temp; // 0...4294967295
   static   unsigned char  buf[20], prescaler, gateTime;
   // アナログの設定
   //ANSEL  = 0b00000000;  // 使用しない。
   CMCON  = 0b00000111;
  // ポートの設定
   TRISA  = 0b11100000;
   TRISB  = 0b01001111;
   OPTION_REG.F7 = 0;      // PORTBをプルアップする。
   // TIMER2の設定
   PIE1.TMR2IE = 1;
   PIR1.TMR2IF = 0;
   T2CON.TOUTPS0 = 0;
   T2CON.TOUTPS1 = 0;
   T2CON.TOUTPS2 = 0;
   T2CON.TOUTPS3 = 0;
   T2CON.TMR2ON = 0;
   T2CON.T2CKPS0 = 1;
   T2CON.T2CKPS1 = 1;
   TMR2 = 0;
   // TIMER1の設定
   PIE1.TMR1IE = 0;
   PIR1.TMR1IF = 0;
   //T1CON.T1RUN = 0;
   T1CON.T1CKPS0 = 0;
   T1CON.T1CKPS1 = 0;
   T1CON.T1OSCEN = 0;
   T1CON.NOT_T1SYNC = 1;
   T1CON.TMR1CS = 1;
   T1CON.TMR1ON = 0;
   TMR1L = 0;
   TMR1H = 0;
   // 変数の初期化
   prescaler = 1;
   gateTime = GATETIME_1SEC;
   // LCD(液晶モニタ)の初期化
   Lcd_Custom_Config(&PORTA,0,1,2,3,&PORTB,4,5,7);
   Lcd_Custom_Cmd(LCD_CURSOR_OFF);
   Lcd_Custom_Out(1, 1, "Freq V7 ");
   Delay_ms(1000);
   Lcd_Custom_Cmd(LCD_CLEAR);
   //
   while (1) {
      // 周波数の測定
      LED = 1;
      freq = FreqMeasurement(gateTime);
      LED = 0;
      //換算
      freq = freq * prescaler * gateTime;
      // プリスケーラの切り替え
      if (sw1 == 1) {
         T1CON.T1CKPS0 = 0;
         T1CON.T1CKPS1 = 0;
         prescaler = 1;
         msg = " 1";
      } else {
         T1CON.T1CKPS0 = 1;
         T1CON.T1CKPS1 = 1;
         prescaler = 8;
         msg = " 8";
//    } else {
//       T1CON.T1CKPS0 = 0;
//       T1CON.T1CKPS1 = 0;
//       prescaler = 8;
//       msg = "64 ";
      }
      Lcd_Custom_Out(2, 2, msg);
      // ゲートタイムの切り替え
      if (sw2 == 1) {
         gateTime = GATETIME_1SEC;
         msg = "1S";
      } else {
         gateTime = GATETIME_100MSEC;
         msg = "01";
      }
      Lcd_Custom_Out(2, 4, msg);
      // -455kHzの有無
      if (sw3 == 0) {
         freq -= 455000;
         msg = "I";
      } else {
         msg = " ";
      }
      Lcd_Custom_Out(2, 1, msg);
      // 表示レンジの切り替え
      if (sw4 == 1) {
         LongToStr(freq, buf);
         msg = " Hz";
      } else {
         temp = freq / 1000;
         if ((freq - (temp * 1000)) > 500) {
            temp++;
         }
         LongToStr(temp, buf);
         msg = "kHz";
      }
      Lcd_Custom_Out(2, 6, msg);
      // 周波数の表示
      Lcd_Custom_Out(1, 1, &buf[3]);
      //
      Delay_ms(500);
   }
}

//**********************************************************************

 


コメント(0) 
前の10件 | -
メッセージを送る