Jago Inserito: 4 aprile 2014 Segnala Share Inserito: 4 aprile 2014 Ciao a tutti, avrei bisogno del vostro aiuto… Mi sono costruito un generatore di onda seguendo un progetto che ho trovato in rete (basato sull'IC XR-2066). Soddisfatto delle prestazioni ho voluto arricchirlo con un frequenzimetro con display LCD (http://unusualelectronics.co.uk/projects/smallprojects/). Questo è il progetto realizzato: http://unusualelectronics.co.uk/projects/smallprojects/. Purtroppo la visualizzazione dei caratteri è corretta solo su display 16X2 (probabilmente anche il 16X1 dato che sfrutta solo la riga superiore) Come si vede dalla foto, lo spazio mi ha consentito l'uso di un 8X2. Guardando l'ASM della PIC (http://www.piclist.com/techref/piclist/weedfreq/4bitlcdusart.htm) sono rimasto ingannato da questa riga: ; #define LCD_8X2 ; LCD is an 8x2 screen Speravo che la visualizzazione fosse prevista per questo tipo di visore, ma ahimè mi tronca i caratteri alla prima metà del classico 16x2 (ho testato un 16X2 "volante" e in effetti la visualizzazione è perfetta..). Ma ormai l'hardware è completo e il display è inutilizzabile… sconforto... Non sapendo veramente nulla si programmazione non ho idea se si possa intervenire sul listato per riprogrammare la PIC (16F628 o 16F84 - ho provato su entrambe..). Essendo un "testone" prima di interpellarvi ho provato a cercare in rete qualche suggerimento a riguardo, ma oltre a questo non ho trovato niente. http://www.piclist.com/techref/piclist/weedfreq8x2LCD.htm . Può essere d'aiuto? L'apparecchio realizzato da me https://www.flickr.com/photos/83771423@N08/13624946144 https://www.flickr.com/photos/83771423@N08/13624949614 https://www.flickr.com/photos/83771423@N08/13624952044 https://www.flickr.com/photos/83771423@N08/13624668433 Vi ringrazio anticipatamente, Jago Pic_counter.zip Link al commento Condividi su altri siti More sharing options...
Livio Orsini Inserita: 4 aprile 2014 Segnala Share Inserita: 4 aprile 2014 (modificato) Non sapendo veramente nulla si programmazione Questo è un bel problema. Un conto è indirizzarti per un'eventuale modifica, altro è parlare una lingua differente. Come hai fatto per programmare il PIC? CHe strumento hai usato? Modificato: 4 aprile 2014 da Livio Orsini Link al commento Condividi su altri siti More sharing options...
GiRock Inserita: 4 aprile 2014 Segnala Share Inserita: 4 aprile 2014 Qui c'è il FIX per LCD 8x2: http://www.piclist.com/techref/piclist/weedfreq8x2LCD.htm Praticamente devi sostituire parte del codice con questo e ricompilare il progetto, le istruzioni sono nel commento iniziale... P.S. Il ; nell'ASM vuol dire che il compilatore ignora la riga o parte di essa... Link al commento Condividi su altri siti More sharing options...
GiRock Inserita: 4 aprile 2014 Segnala Share Inserita: 4 aprile 2014 Non so se hai capito bene il discorso!!! Prima prova a togliere il ; dal #define LCD_8X2 e ricompila, se ancora non va bene, allora devi usare il FIX come spiegato e solo per certe tipologie di 8x2... Se non lo sai fare, l'ho già fatto io e funziona, al limite ti posto l'HEX... Link al commento Condividi su altri siti More sharing options...
Jago Inserita: 5 aprile 2014 Autore Segnala Share Inserita: 5 aprile 2014 Andiamo per ordine... Intanto grazie per le risposte. Per Livio: ho compilato il file HEX con MPLAE IDE v8.56 (con un semplice Quickbuild). Poi ho programmato il PIC (sia il 16F84 che il 16F628) con un programmatore di mia costruzione sulla seriale di un vecchio PC. Il programma utilizzato è WinPIC perchè IcProg ha problemi col 16F628 (errore h0000). Per GiRock: ho provato a togliere il punto e virgola al ; define LCD_8x2 ma a questo punto il compliatore dà errore e non mi crea più l'HEX. Ho notato che tu hai inserito nel tuo post un simbolo cancelletto attaccato alla parola define (nel listato non c'è, devo aggiungerlo?). Io ho già provato a guardare il listato per la modifica che avevo trovato in rete, ma non ho trovato il comando "shift"... fino a "sub" quindi non mi sono azzardato a maciullare il file. Non capisco... scusa, ma mi piacerebbe molto capirlo per farlo autonomamente (se possibile...) Bye Link al commento Condividi su altri siti More sharing options...
GiRock Inserita: 5 aprile 2014 Segnala Share Inserita: 5 aprile 2014 Il cancelletto lo devi lasciare, altrimenti da giustamente errore dato che la sintassi non è corretta, comunque io l'ho compilato e non da nessun errore, quelli che vedi sono solo dei WARNING, per non visualizzarli scrivi questo dopo la config-word: ERRORLEVEL -302... Il FIX è per display obsoleti, magari il tuo non ne necessita, ad ogni modo se lo devi poi provare, te lo faccio vedere io dove deve essere messo, ho visto che bisogna modificare anche delle call che non hanno lo stesso nome, quindi andrebbe un FIX del FIX... P.S. Occhio che il compilatore fa distinzione anche tra un codice scritto ad inizio riga ed uno spaziato, quindi non toccare nulla del codice originale, togli il ; e tieni spaziato il #define LCD_8x2... Link al commento Condividi su altri siti More sharing options...
Jago Inserita: 5 aprile 2014 Autore Segnala Share Inserita: 5 aprile 2014 Ho provato a fare quello che hai detto: tolto ; e mantenuto spazio. Dopo i config ho inserito ERRORLEVEL -302 e in effetti il complilatore ha prodotto l'HEX, ma niente, ora non viene visualizzato niente e sembra addirittura che la prima riga superiore abbia tutto il display con le "celle" annerite... Temo che dovrò fare quello che avevi paventato: cioè sostituire quel pezzo di codice. Quando hai tempo e voglia mi spieghi cosa devo fare oppure se preferisci, ed magari più semplice per te, mi mandi l'asm. Poi per compilarlo ci penso io. Mi spiace molto, ma ho finito le risorse... Jago Link al commento Condividi su altri siti More sharing options...
GiRock Inserita: 5 aprile 2014 Segnala Share Inserita: 5 aprile 2014 Prima prova con il mio HEX che sono sicuro che è settato correttamente, poi vediamo di fare un FIX... :020000040000FA :100000001229C7000408C60045088400470880007C :10001000C50A840A80014608840047080800803029 :10002000D02037308400000803191928CE20840A14 :10003000132808000530B200A530B300B30B1E280A :10004000B20B1C280034B6132408A10203182F2871 :100050000130A20203182F28A302031CB61725089B :10006000A202031837280130A302031CB617260882 :10007000A302031CB61700342408A107031C43285D :10008000A20F4328A30A2508A2070318A30A2608DB :10009000A30700340730B2002B3084002F308000DB :1000A000840AB20B4F280F30A6004230A500403022 :1000B000A4002320AB0A3A302B0603192E2AB61FC0 :1000C00059283C200130A6008630A500A030A400AD :1000D0002320AC0AB61F68283C20A6012730A500C3 :1000E0001030A4002320AD0AB61F72283C20033034 :1000F000A500E830A4002320AE0AB61F7B283C20D0 :10010000A5016430A4002320AF0AB61F83283C2039 :100110000A30A4002320B00AB61F8A283C202108F8 :10012000B107B10A003483163730810083161030CE :100130008500831285110511A3018101AA0105150E :1001400005112008B2008515FA30B300AD28000073 :10015000000000000000000000000108AA02031DCA :10016000B3280000B5280318A30AAA000000000065 :100170000000B30BA728B20BA42885110108A20028 :10018000AA02031CC528031DA30AA101A10305158A :100190000511010822060319C62800340515D128C7 :1001A0000511C800C90085100F308316860583121B :1001B000F030C8050F30C905C90E06080F394804CC :1001C000860005140000051006080F394904860052 :1001D000051400000510F720C800C81FF028EB2800 :1001E00008304806031D0800C430D0200800F03055 :1001F000831686048312051100008514000005147F :10020000000006080510C8000514F030C805060EE9 :1002100005100F39C80485100F3083168605831228 :100220004808080085011030831685008312860176 :1002300006308316860083120F3086053030860420 :100240000514000005101A201A20051400000510DE :100250003230C700C70B2A29051400000514061206 :1002600000000514000005100F30C700C70B362929 :100270002830D0200C30D0200130D0200630D020C3 :100280008030D0201430A00093204A2030302B063C :10029000031D4E2930302C0603198E293730C50036 :1002A0000230B2002B30840030300006031D5E297E :1002B00020300120840AB20B542963290008012050 :1002C000840AB20B5E292E3001200530B2000008EE :1002D0000120840AB20B6729203001204D30012013 :1002E000483001207A3001202030012020300120C8 :1002F0000F2042291430A00093204A2030302B06D2 :10030000031D4E2932302C0203184E2930302C06A2 :10031000031D8E2930302D060319B8293730C5004A :100320000530B2002B30840030300006031D9E29BA :1003300020300120840AB20B9429A329000801204F :10034000840AB20B9E292E30012000080120840A65 :1003500000080120203001206B30012048300120AE :100360007A30012020300120203001200F207A290E :10037000C830A00093204A2030302B06031D7A2974 :1003800032302C0203187A2930302C06031DCC2978 :1003900030302D060319092A3730C5000430B20069 :1003A0002B30840030300006031DDC292030012072 :1003B000840AB20BD229E12900080120840AB20B79 :1003C000DC292E30012000080120840A00080120C9 :1003D000840A00080120203001206B3001204830C1 :1003E00001207A30012020300120203001200F2010 :1003F000B829C830A00093204A2030302B06031DB6 :10040000CC2930302C06031DCC2932302D020318A4 :10041000CC293730C5000730B2002B308400303093 :100420000006031D192A20300120840AB20B0F2A6E :100430001E2A00080120840AB20B192A203001204C :10044000483001207A300120203001202030012066 :1004500020300120203001200F20F9290130D02048 :100460003730C5004F300120763001206530012043 :1004700072300120663001206C3001206F30012085 :0C048000773001200F200230D0204229EC :02400E00F13F80 :00000001FF Link al commento Condividi su altri siti More sharing options...
GiRock Inserita: 5 aprile 2014 Segnala Share Inserita: 5 aprile 2014 Ahahahah, mi sono accorto ora che il FIX è per le vecchie versioni del codice tipo questa: http://www.piclist.com/techref/piclist/weedfreq/WCT6.htm Comunque io l'ho modificato e fatto stare in quell'altro codice, non posso però assicurarti che vada bene, sul 16x2 non vedo ritorni a capo mentre prima si, ad ogni modo nella seconda riga viene visualizzato solo Hz o Khz... Link al commento Condividi su altri siti More sharing options...
Jago Inserita: 5 aprile 2014 Autore Segnala Share Inserita: 5 aprile 2014 Ciao, ho provato con l'HEX che mi hai copiato nel POSt. In effetti si programma a buon fine, ma il risultato ahimè non cambia... riga superiore tutta scura riga inferiore bianca. Cosa consigli? Ma l'assembler che vedo nel tuo ultimo post è ciò che fa per me? bye Link al commento Condividi su altri siti More sharing options...
GiRock Inserita: 5 aprile 2014 Segnala Share Inserita: 5 aprile 2014 Allora, io ti metto il codice attuale con FIX incluso, se non funziona, bisogna ricorrere alla versione precedente ed applicarlo a quella che ti ho linkato... ;****************************************************************************** ; FREQUENCY COUNTER ; Model : WTCNT ; Author : Barry Smith (tron at zoidberg dot nl) ; Date : April 2006 ; Version: 0.1 ; ; Adapted from original code by Terry J. Weeder (WWW.WEEDTECH.COM) ; ; The main differences between this code and the original code are: ; ; - Code ported to the 16F628 (should work on all 16F6xx chips) ; ; - Data also sent to USART port to allow PC to read frequency. ; ; - LCD interface modified to 4 data lines to free up I/O pins ; ; - Code uses MPASM include file for all register definitions ; ; - Various code tweaks and changes ; ; Distributed under the GNU public license. This code may be used in ; commercial products provided this source code is also made available. ; If this code is modified the modified source must be made available. ; ;****************************************************************************** IFDEF __16F84A include p16f84a.inc __CONFIG(_CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC) ENDIF IFDEF __16F628 include p16f628.inc __CONFIG(_BODEN_OFF & _CP_OFF & _DATA_CP_OFF & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _MCLRE_OFF & _XT_OSC) #define SERIAL_OUT ; Send data via USART ENDIF ERRORLEVEL -302 ; #define NO_LCD ; Define to work without LCD present (eg RS232 only) #define LCD_8X2 ; LCD is an 8x2 screen LCD_E equ 0 ; Port A, bit 0 LCD_RW equ 1 ; Port A, bit 1 LCD_RS equ 2 ; Port A, bit 2 OVRFLW equ 7 IFDEF LCD_8X2 LCD_START equ 0x80 ; Start address on display ELSE LCD_START equ 0x82 ENDIF CBLOCK 0x20 gate cnt1, cnt2, cnt3 calc1, calc2, calc3 sum1, sum2, sum3 rtcc2 DIGITS:0x07 count1 count2 in_reg addcnt status2 TBUF:0x0E ; Text Buffer TBUF_PTR ; Current position in tbuffer TSAVE ; Save INDF when using tbuffer TWTMP ; Also used in text buffering LW_HIGH LW_LOW ENDC ; ORG 0 goto start ; ; Writes a character to the end of the text buffer ; Preserves: W, FSR ; Destroys : STATUS tbuffer movwf TWTMP ; Save W movf FSR, W ; Save FSR movwf TSAVE movf TBUF_PTR, W ; Assign pointer to FSR movwf FSR movf TWTMP, W ; Write W value to pointer location movwf INDF incf TBUF_PTR, F ; Increment pointer.. incf FSR, F ; .. and null terminate string. clrf INDF movf TSAVE, W ; Restore FSR movwf FSR movf TWTMP, W ; restore W, in case its useful return ; ; Writes the contents of the tbuffer out tbuffer_out IFNDEF NO_LCD ; LCD only section movlw LCD_START call lcd_inst_out movlw TBUF movwf FSR tbo_loop movf INDF, W btfsc STATUS, Z goto tbo_out2 call lcd_data_out incf FSR, F goto tbo_loop ENDIF ; End LCD only section tbo_out2 IFDEF SERIAL_OUT movlw TBUF movwf FSR tbo_loop2 movf INDF, W btfsc STATUS, Z goto tbo_end call tx_data_out incf FSR, F goto tbo_loop2 tbo_end movlw '\n' ; Newline terminate call tx_data_out ENDIF return IFDEF SERIAL_OUT tx_data_out btfss PIR1, TXIF goto tx_data_out ; Wait for buffer to empty movwf TXREG return ENDIF ; int_del movlw 0x05 ;delay 2.5 ms (4 MHz clock) movwf count1 d1 movlw 0xA5 movwf count2 d2 decfsz count2 ,f goto d2 decfsz count1 ,f goto d1 retlw 0x00 ; sub bcf status2,OVRFLW ;clear overflow bit movf calc1,w ;subtract calc1 from cnt1 subwf cnt1 ,f btfsc STATUS,C goto sb1 movlw 0x01 ;borrow from cnt2 if overflow subwf cnt2 ,f btfsc STATUS,C goto sb1 subwf cnt3 ,f ;borrow from cnt3 if cnt2 overflow btfss STATUS,C bsf status2,OVRFLW ;set overflow bit if result is negative sb1 movf calc2,w ;subtract calc2 from cnt2 subwf cnt2 ,f btfsc STATUS,C goto sb2 movlw 0x01 ;borrow from cnt3 if cnt2 overflow subwf cnt3 ,f btfss STATUS,C bsf status2,OVRFLW ;set overflow bit if result is negative sb2 movf calc3,w ;subtract calc3 from cnt3 subwf cnt3 ,f btfss STATUS,C bsf status2,OVRFLW ;set overflow bit if result is negative retlw 0x00 ; add movf calc1,w ;add calc1 to cnt1 addwf cnt1 ,f btfss STATUS,C goto ad1 incfsz cnt2 ,f ;add to cnt2 if cnt1 overflow goto ad1 incf cnt3 ,f ;add to cnt3 if cnt2 overflow ad1 movf calc2,w ;add calc2 to cnt2 addwf cnt2 ,f btfsc STATUS,C incf cnt3 ,f ;add to cnt3 if cnt2 overflow movf calc3,w ;add calc3 to cnt3 addwf cnt3 ,f retlw 0x00 ; ; Begin by writing '/' (or 0x2F) to DIGITS+0 - 7 cnvt movlw 0x07 ;7 digits in display movwf count1 movlw DIGITS+0 ;set FSR for MSB in display movwf FSR movlw 0x2F ;one less that ASCII "0" cnvt0 movwf INDF incf FSR ,f decfsz count1,F goto cnvt0 movlw 0x0F ;load "1,000,000" in calc1-3 (0x0F4240) movwf calc3 movlw 0x42 movwf calc2 movlw 0x40 movwf calc1 cnvt1 call sub ;subtract number from count incf DIGITS+0 ,f ;increment 1,000,000's register movlw 0x3A xorwf DIGITS+0,w btfsc STATUS,Z goto overflow btfss status2,OVRFLW ;check if overflow goto cnvt1 call add ;add back last number movlw 0x01 ;load "100,000" in calc1-3 movwf calc3 movlw 0x86 movwf calc2 movlw 0xA0 movwf calc1 cnvt2 call sub ;subtract number from count incf DIGITS+1 ,f ;increment 100,000's register btfss status2,OVRFLW ;check if overflow goto cnvt2 call add ;add back last number clrf calc3 ;load "10,000" in calc1-3 movlw 0x27 movwf calc2 movlw 0x10 movwf calc1 cnvt3 call sub ;subtract number from count incf DIGITS+2 ,f ;increment 10,000's register btfss status2,OVRFLW ;check if overflow goto cnvt3 call add ;add back last number movlw 0x03 ;load "1,000" in calc1-3 movwf calc2 movlw 0xE8 movwf calc1 cnvt4 call sub ;subtract number from count incf DIGITS+3 ,f ;increment 1,000's register btfss status2,OVRFLW ;check if overflow goto cnvt4 call add ;add back last number clrf calc2 ;load "100" in calc1-3 movlw 0x64 movwf calc1 cnvt5 call sub ;subtract number from count incf DIGITS+4 ,f ;increment 100's register btfss status2,OVRFLW ;check if overflow goto cnvt5 call add ;add back number movlw 0x0A ;load "10" in calc1-3 movwf calc1 cnvt6 call sub ;subtract number from count incf DIGITS+5 ,f ;increment 10's register btfss status2,OVRFLW ;check if overflow goto cnvt6 call add ;add back last number movf cnt1,w ;put remainder in 1's register addwf DIGITS+6 ,f incf DIGITS+6 ,f retlw 0x00 ; count BANKSEL OPTION_REG movlw b'00110111' ;rtcc = ext, 1/256 movwf OPTION_REG BANKSEL TRISA movlw b'00010000' ;define PORTA as output movwf TRISA BANKSEL PORTA bcf PORTA,3 bcf PORTA,2 clrf cnt3 clrf TMR0 clrf rtcc2 bsf PORTA,2 ;toggle rtcc pin bcf PORTA,2 movf gate,w ;get gate time movwf count1 bsf PORTA,3 ;start count fr4 movlw 0xFA movwf count2 goto fr6 fr5 nop nop nop nop nop nop fr6 movf TMR0,w ;test for rtcc rollover (12) subwf rtcc2 ,f btfss STATUS,Z goto fr7 nop goto fr8 fr7 btfsc STATUS,C incf cnt3 ,f fr8 movwf rtcc2 nop nop nop decfsz count2 ,f goto fr5 decfsz count1 ,f goto fr4 bcf PORTA,3 ;stop count movf TMR0,w ;get rtcc count movwf cnt2 subwf rtcc2 ,f ;test for rtcc rollover btfss STATUS,C goto fr9 btfss STATUS,Z incf cnt3 ,f fr9 clrf cnt1 ;set to get prescaler count fr10 decf cnt1 ,f bsf PORTA,2 ;toggle rtcc pin bcf PORTA,2 movf TMR0,w ;test if rtcc has changed xorwf cnt2,w btfsc STATUS,Z goto fr10 retlw 0x00 ; ; IFNDEF NO_LCD lcd_data_out bsf PORTA, LCD_RS goto lcd_w_out lcd_inst_out bcf PORTA, LCD_RS ; ; 4 bit W out routine ; lcd_w_out movwf LW_HIGH movwf LW_LOW bcf PORTA, LCD_RW movlw b'00001111' ; Set RB7:4 as outputs BANKSEL TRISB andwf TRISB, F BANKSEL PORTB movlw b'11110000' andwf LW_HIGH, F movlw b'00001111' andwf LW_LOW, F swapf LW_LOW, F ; Now LW_HIGH = 7654xxxx, LW_LOW = 3210xxxx from orig. W movf PORTB, W andlw b'00001111' iorwf LW_HIGH, W movwf PORTB ; Writes high order bits out bsf PORTA, LCD_E nop bcf PORTA, LCD_E movf PORTB, W andlw b'00001111' iorwf LW_LOW, W movwf PORTB ; Writes low order bits out bsf PORTA, LCD_E nop bcf PORTA, LCD_E lcd_busy_wait call lcd_w_in movwf LW_HIGH btfss LW_HIGH, 7 goto lcd_shift goto lcd_busy_wait ; lcd_shift IFDEF LCD_8X2 ; ORIGINAL 8x2 ; movlw 0x08 ; xorwf LW_HIGH, W ; btfss STATUS, Z ; return ; movlw 0xC4 ; call lcd_inst_out ; ; FIX 8x2 ; ;********************************************************************* ;* WEEDER FREQUENCY COUNTER ;* Fix for 2 line (8x2) displays that were sold as 16x1 displays ;* ;* Because most of these displays lack a controller chip ;* it is required that the code manually sets the address for the ;* 9th char. That is what this code does. ;* ;* Questions? ;* Drop me an e-mail cklymko[at]hotmail.com ;* ;* Scroll through your code and locate "Shift". ;* Paste the following code starting with "Shift" and ending ;* just before the first "sub" command. ;* ;********************************************************************* shift btfsc addcnt,6 ;added for 8x2 displays goto shift2 ; ; btfsc addcnt,3 ; ; goto line2 ;end the 8x2 code btfss addcnt,0 ;shift to opposite side of display? retlw 0x00 btfss addcnt,1 retlw 0x00 btfss addcnt,2 retlw 0x00 goto line2 ; btfss addcnt,3 retlw 0x00 line2 movlw 0xB8 ;Force the second line. addwf addcnt,f bsf addcnt,7 movf addcnt,w goto lcd_inst_out ;********************************************************************* ; added to move back to home position. ;********************************************************************* shift2 btfsc addcnt,3 ; goto line1 btfss addcnt,0 ;shift to opposite side of display? retlw 0x00 btfss addcnt,1 retlw 0x00 btfss addcnt,2 retlw 0x00 ; btfss addcnt,3 retlw 0x00 line1 movlw 0x39 addwf addcnt,f bsf addcnt,7 movf addcnt,w goto lcd_inst_out ENDIF return ; ; Routine to read the BF/Addr information from the LCD ; lcd_w_in movlw b'11110000' ; Set RB7:4 as inputs BANKSEL TRISB iorwf TRISB, F BANKSEL PORTB bcf PORTA, LCD_RS nop ; Safety nop bsf PORTA, LCD_RW nop ; Safety nop bsf PORTA, LCD_E ; Trigger read (high bits) nop movf PORTB, W bcf PORTA, LCD_E ; Clock low movwf LW_HIGH bsf PORTA, LCD_E ; Trigger read (low bits) movlw b'11110000' andwf LW_HIGH, F swapf PORTB, W bcf PORTA, LCD_E andlw b'00001111' iorwf LW_HIGH, F bcf PORTA, LCD_RW movlw b'00001111' ; Reset RB7:4 as outputs BANKSEL TRISB andwf TRISB, F BANKSEL PORTB movf LW_HIGH, W return ENDIF ; end LCD only section ; ;****************************************************************************** ; START ;****************************************************************************** ; start clrf PORTA ;instruction, write, enable low IFDEF __16F628 movlw 0x07 movwf CMCON ENDIF movlw b'00010000' BANKSEL TRISA movwf TRISA BANKSEL PORTB clrf PORTB movlw b'00000110' ; For 628 RX/TX must be inputs BANKSEL TRISB movwf TRISB BANKSEL PORTB IFDEF SERIAL_OUT BANKSEL SPBRG movlw d'25' ; 9600 baud (with BRGH=1) movwf SPBRG BANKSEL TXSTA bcf TXSTA, SYNC bsf TXSTA, TXEN bsf TXSTA, BRGH BANKSEL RCSTA bsf RCSTA, SPEN ENDIF IFNDEF NO_LCD ; It is necessary to wait for 15ms after Vcc rises to ; 4.5V and 40ms after it rises to 2.7V. However, as we ; use PWRTE_ON which gives a 72ms delay, this should be ; fine and we should need no extra delay here. ; movlw b'00001111' ; Note: PORTA is low so RS & RW andwf PORTB,F ; are both 0. movlw b'00110000' ; Puts 0011 on lcd D7:D4 iorwf PORTB, F ; yes, this does mean 8 bit! bsf PORTA,LCD_E ; toggle enable nop bcf PORTA,LCD_E call int_del call int_del ; Wait at least 4.1ms (5ms here) bsf PORTA,LCD_E ; Send 8-bit initialise again... nop bcf PORTA,LCD_E movlw d'50' ; Now need 100us delay movwf TWTMP lcd_init_del1 decfsz TWTMP, F goto lcd_init_del1 ; about 150us in fact... bsf PORTA, LCD_E ; Yet again we set it to 8-bit nop ; what a wierd initialisation bsf PORTA, LCD_E ; this is! bcf PORTB, 4 ; Change 8 line -> 4 line nop bsf PORTA,LCD_E ; Finally we can send the 4-bit init nop bcf PORTA,LCD_E movlw d'15' ; Now need 40us delay movwf TWTMP lcd_init_del2 decfsz TWTMP, F goto lcd_init_del2 ; about 150us in fact... ; Finally we can send 4-bit instructions, starting with ; the yet another initialisation instruction. movlw b'00101000' ;initialise (again) call lcd_inst_out movlw b'00001100' ;display on, cursor off call lcd_inst_out movlw b'00000001' ;clear display call lcd_inst_out movlw b'00000110' ;entry mode call lcd_inst_out movlw b'10000000' ;cursor to start call lcd_inst_out ENDIF ; end LCD only section ; mhz movlw 0x14 ;0.1 sec gate movwf gate call count call cnvt ;convert binary to ASCII ; ; If first 2 digits are zeros, goto khz1, otherwise mhz1 ; movlw '0' ;test if "0" xorwf DIGITS+0,w btfss STATUS,Z goto mhz1 movlw '0' ;if 1st digit is 0... test if "0" xorwf DIGITS+1,w btfsc STATUS,Z goto khz1 mhz1 movlw TBUF ; Reset TBUF pointer movwf TBUF_PTR movlw 0x02 ;output first 2 characters movwf count1 movlw DIGITS+0 ;MSD of freq movwf FSR ; ; mhz2/mhz3 loop puts out 2 (count1) digits, printing spaces for leading zeros. ; mhz2 movlw '0' ;test if "0" xorwf INDF,w btfss STATUS,Z goto mhz3 movlw ' ' ;change preceeding "0's" to "space" call tbuffer incf FSR ,f decfsz count1 ,f goto mhz2 goto mhz4 mhz3 movf INDF,w call tbuffer incf FSR ,f decfsz count1,f goto mhz3 ; ; We know we're dealing with Mhz here, or we would have jumped to kHz ; by now, so put out '.' ; mhz4 movlw '.' call tbuffer movlw 0x05 ;output last 5 characters movwf count1 mhz5 movf INDF,w call tbuffer incf FSR ,f decfsz count1 ,f goto mhz5 movlw ' ' call tbuffer movlw 'M' call tbuffer movlw 'H' call tbuffer movlw 'z' call tbuffer movlw ' ' call tbuffer movlw ' ' call tbuffer call tbuffer_out goto mhz ; ; If first 2 digits were 00 then we try here for kHz ; khz movlw 0x14 ;0.1 sec gate movwf gate call count call cnvt ;convert binary to BCD movlw '0' ;test if 0 xorwf DIGITS+0,w btfss STATUS,Z goto mhz1 movlw '2' ;test if < 2 subwf DIGITS+1,w btfsc STATUS,C goto mhz1 movlw '0' ;test if "0" xorwf DIGITS+1,w btfss STATUS,Z goto khz1 movlw '0' ;test if "0" xorwf DIGITS+2,w btfsc STATUS,Z goto xkhz khz1 movlw TBUF ; Reset TBUF pointer movwf TBUF_PTR movlw 0x05 ; output first 5 characters movwf count1 movlw DIGITS+0 ; MSD of freq movwf FSR khz2 movlw '0' ; test if "0" xorwf INDF,w btfss STATUS,Z goto khz3 movlw ' ' ; change preceeding "0's" to "space" call tbuffer incf FSR ,f decfsz count1 ,f goto khz2 goto khz4 khz3 movf INDF,w call tbuffer incf FSR ,f decfsz count1 ,f goto khz3 khz4 movlw '.' call tbuffer movf INDF,w ;output last 2 characters call tbuffer incf FSR ,f movf INDF,w call tbuffer movlw ' ' call tbuffer movlw 'k' call tbuffer movlw 'H' call tbuffer movlw 'z' call tbuffer movlw ' ' call tbuffer movlw ' ' call tbuffer call tbuffer_out goto khz ; ; Now routines with modified 1 sec gates for < 100kHz ; xkhz movlw 0xC8 ;1 sec gate movwf gate call count call cnvt ;convert binary to BCD movlw '0' ;test if 0 xorwf DIGITS+0,w btfss STATUS,Z goto khz movlw '2' ;test if < 2 subwf DIGITS+1,w btfsc STATUS,C goto khz movlw '0' ;test if 0 xorwf DIGITS+1,w btfss STATUS,Z goto xkhz1 movlw '0' ;test if 0 xorwf DIGITS+2,w btfsc STATUS,Z goto hz0 xkhz1 movlw TBUF ; Reset TBUF pointer movwf TBUF_PTR movlw 0x04 ;output first 4 characters movwf count1 movlw DIGITS+0 ;MSD of freq movwf FSR xkhz2 movlw '0' ;test if "0" xorwf INDF,w btfss STATUS,Z goto xkhz3 movlw ' ' ;change preceeding "0's" to "space" call tbuffer incf FSR ,f decfsz count1 ,f goto xkhz2 goto xkhz4 xkhz3 movf INDF,w call tbuffer incf FSR ,f decfsz count1 ,f goto xkhz3 xkhz4 movlw '.' call tbuffer movf INDF,w ;output last 3 characters call tbuffer incf FSR ,f movf INDF,w call tbuffer incf FSR ,f movf INDF,w call tbuffer movlw ' ' call tbuffer movlw 'k' call tbuffer movlw 'H' call tbuffer movlw 'z' call tbuffer movlw ' ' call tbuffer movlw ' ' call tbuffer call tbuffer_out goto xkhz ; hz movlw 0xC8 ;1 sec gate movwf gate call count call cnvt ;convert binary to BCD movlw '0' ;test if "0" xorwf DIGITS+0,w btfss STATUS,Z goto xkhz1 movlw '0' ;test if "0" xorwf DIGITS+1,w btfss STATUS,Z goto xkhz1 movlw '2' ;test if < 2 subwf DIGITS+2,w btfsc STATUS,C goto xkhz1 hz0 movlw TBUF ; Reset TBUF pointer movwf TBUF_PTR movlw 0x07 ;output first 7 characters movwf count1 movlw DIGITS+0 ;MSD of freq movwf FSR hz1 movlw '0' ;test if "0" xorwf INDF,w btfss STATUS,Z goto hz2 movlw ' ' ;change preceeding "0's" to "space" call tbuffer incf FSR ,f decfsz count1 ,f goto hz1 goto hz3 hz2 movf INDF,w call tbuffer incf FSR ,f decfsz count1 ,f goto hz2 hz3 movlw ' ' call tbuffer movlw 'H' call tbuffer movlw 'z' call tbuffer movlw ' ' call tbuffer movlw ' ' call tbuffer movlw ' ' call tbuffer movlw ' ' call tbuffer call tbuffer_out goto hz ; overflow IFNDEF NO_LCD movlw 0x01 ;clear display call lcd_inst_out ENDIF movlw TBUF ; Reset TBUF pointer movwf TBUF_PTR movlw 'O' call tbuffer movlw 'v' call tbuffer movlw 'e' call tbuffer movlw 'r' call tbuffer movlw 'f' call tbuffer movlw 'l' call tbuffer movlw 'o' call tbuffer movlw 'w' call tbuffer call tbuffer_out IFNDEF NO_LCD movlw 0x02 ;cursor at home call lcd_inst_out ENDIF goto mhz END Link al commento Condividi su altri siti More sharing options...
Jago Inserita: 5 aprile 2014 Autore Segnala Share Inserita: 5 aprile 2014 Progressi GiRock, questo ultimo file compilato e scritto su entrambe i modelli di PIC danno il medesimo risultato. La cifra ora è leggibile per esteso senza cifre tagliate, ma purtroppo sulla riga inferiore non c'è l'etichetta Hz o KHz... Grazie per la pazienza. Non voglio approfittarne oltre, nella peggiore delle ipotesi me lo terrò così, l'unità di misura la posso immaginare. Con gratitudine, Jago Link al commento Condividi su altri siti More sharing options...
GiRock Inserita: 5 aprile 2014 Segnala Share Inserita: 5 aprile 2014 Purtroppo non posso fare ulteriori test non avendo il tuo modello di dispaly, però ti posso suggerire alcune cose: 1) Se noti nel FIX ci sono delle righe commentate con il punto e virgola, potresti provare a vedere cosa succede abilitandole una alla volta, nel 16x2 non cambia niente2) Testa il codice precedente a questo con il FIX, li è presente la label SHIFT ed è facile da implementare3) Fai una ricerca sugli 8x2 in rete e vedi cosa dicono4) Lascia tutto così com'è e Amen Ti saluto, se mi vengono in mente idee le posto qui, sempre ammesso che tu voglia continuare il discorso, ma non subito... Link al commento Condividi su altri siti More sharing options...
Jago Inserita: 5 aprile 2014 Autore Segnala Share Inserita: 5 aprile 2014 EUREKA!!!!! Siamo riusciti finalmente. Ho fatto decine di prove sminuzzando e copiando qua e là, ma alla fine ce l'abbiamo fatta. Il problema nasceva anche dal fatto che copiando il listato dal txt da un Mac qualche simbolo o spazio causava casini. Ho operato allora sul vecchio PC e ho cominciato le prove da capo. Tolto il punto e virgola dal primo listato e programmato su un PIC16F628, le etichette sotto sono comparse, gli allineamenti sono un po' "improbabili" ma non importa, il lavoro si presenta bene e ora posso chiudere lo chassis. Non so come avrei fatto senza di voi. Ho un generatore di onde! Adesso comincia la parte divertente... mi sono regalato un oscilloscopio Rigol e ora si aprono nuovi orizzonti da scoprire e da imparare! GiRock sei un mito! Buona notte Link al commento Condividi su altri siti More sharing options...
Jago Inserita: 7 aprile 2014 Autore Segnala Share Inserita: 7 aprile 2014 Ciao, allego immagini del successo... https://www.flickr.com/photos/83771423@N08/13695797883 https://www.flickr.com/photos/83771423@N08/13696120524 Se volessi usare l'oggetto anche come generatore di suono, per testare i miei preamplificatori di piezopickup (guadagno e qualità) o amplificatori per chitarra, come consigliate di eliminare la parte DC dell'uscita? Con un condensatore, trasformatore? Bye, Jago Link al commento Condividi su altri siti More sharing options...
Livio Orsini Inserita: 7 aprile 2014 Segnala Share Inserita: 7 aprile 2014 Complimenti per la realizzazione. Bel lavoro. Link al commento Condividi su altri siti More sharing options...
Jago Inserita: 7 aprile 2014 Autore Segnala Share Inserita: 7 aprile 2014 Grazie Livio, i tuoi complimenti fanno sempre un grande piacere... Link al commento Condividi su altri siti More sharing options...
Livio Orsini Inserita: 8 aprile 2014 Segnala Share Inserita: 8 aprile 2014 però ti converrebbe imparare a programamre, visto che hai questa passione per l'elettronica. Link al commento Condividi su altri siti More sharing options...
Jago Inserita: 9 aprile 2014 Autore Segnala Share Inserita: 9 aprile 2014 Lo so, non hai idea quanto vorrei, ma a 46 anni, con un diploma di perito grafico, marito e padre di due ragazze in piena adolescenza, con uno studio proprio... faccio un po' fatica a tornare sui banchi di scuola. Mi servirebbe un'altra vita o andare in pensione! Comunque con voi sto imparando un sacco di cose e un passino alla volta. Ho già cominciato a far a accendere e spegnere un LED (basterebbe un interruttore )! In effetti è vergognoso che in questi anni ho programmato decine di PIC di tutti i generi e dimensioni senza mai approfondire il tema della programmazione. Ricordo di aver cominciato con il Basic sul Vic20 in piena rivoluzione informatica, quand'ero ragazzino, ma la vita, il lavoro e la passione per l'arte mi hanno portato altrove. Ma i miei hobby sono e saranno sempre la musica, gli hifi meglio se autocostruiti, il design e la liuteria... quindi l'elettronica è il legante di tutto ciò e, malgrado le mie lacune, mi dà molta soddisfazione. Una buona giornata e un caro saluto, grazie. Link al commento Condividi su altri siti More sharing options...
Livio Orsini Inserita: 9 aprile 2014 Segnala Share Inserita: 9 aprile 2014 ma a 46 anni, con un diploma di perito grafico, marito e padre di due ragazze in piena adolescenza, Intanto ti esprimo tutta la mia solidarietà! Questa, delle 2 figlie adolescenti più moglie, è una situazione che ho vissuto anch'io. Conosco bene il problema. Però ti garantisco che, visto che sei una persona a cui non infastidisce cimentarsi in cose nuove, non è poi così difficile imparare a programmare. Sul webb trovi tantissimi tutorials che insegnano a programmare i micro. Ad esempio prova a scaricarti il tutorial di Sergio Tanzilli, è quasi un oggetto di culto per chi inizia con i PIC. Vedrai che le cose son molto più semplici di quello che pensi Poi a 46 anni si è dei giovanatti pieni di enrgia, te lo dice uno che di anni ne ha quasi 70. Se mi guardo indietro a quell'età mi pare fossi ancora un qausi adolescente. Link al commento Condividi su altri siti More sharing options...
Messaggi consigliati
Crea un account o accedi per commentare
Devi essere un utente per poter lasciare un commento
Crea un account
Registrati per un nuovo account nella nostra comunità. è facile!
Registra un nuovo accountAccedi
Hai già un account? Accedi qui.
Accedi ora