Справочници, схемотехника, теория > Програмиране на микроконтролери, програматори, цифрови проекти
Цифров манометър за под 50 лева
juliang:
На пазара няма нищо освен манометри за помпане на гуми, които бъркат с 1 бар. Ровейки в нета, ми излезна една сергийка в Алиекспрес, де човека предлага трансмитери за налягане с всякакви обхвати - от 300 миибара до стотици бара. Поръчах си един който мери от -1 бар до +2 бара. С'я ме е яд, е не поъчах още един от 0 до 300 милибара, но не е късно.
Трансмитера се захранва с 5 волта, сигнала му е 0.5-4.5 волта и струва към 24 лева. Ардуино Нано имам да се порина - преди време купих 10 за по долар парчето... не ми се чакаше оещ един месец та похарчих някъде към 8 лева в Комет за един ОЛЕД дисплей 128 х 32 точки. Той па се захранва с 3.3 волта... ама това не е никакъв проблем щот Нано-то си има изходи и за 5, и за 3.3 волта.
Батерийка 9 волта за захранване и кутийка от Елимекс, в която всичко влезна сякаш за това е правено. Бутон за нулиране и ключе за вкл/изкл - тия неща също ми се търкаляха из шкафа от разни стари проекти. Кутийката я взех днес, та още не съм пробил отвора за диспеля.
Кода за ардуиното е 20 реда. Ако се сетя утре, ще го пусна, ама няма нищо интересно - чета аналогов вход, Умножавам го с някакъв коефициент за да направя от 0.5 - 4.5 волта -1000 - 2000 милибара, и го пиша на дисплея.
Кат си поръчам другия трансмитер за налягане, ще трябва да измисля начин как да превключвам коефициента спрямо другия обхват, ама това е за по-нататък. Изводите са им стандартизирани така че ще ползвам щекера който си върви на кабела за всеки от трансмитерите.
Първия тест на бюрото показва макс 2 милибара отклонение спрямо манометърчето на Тесто от магазина, поне до 150 милибара.
juliang:
--- Цитат на: EDM electronics в Март 09, 2023, 11:32:58 am ---...Ти не знаеш ли кой е теоретика на форума и дървен философ с общо над 23 000 поста във форуми? Не е нормално до имаш 23 000 поста теории и обяснения колко сме кадърни и нито едно нещо на практика. Това е дървения философ. Той сам ще ти се покаже, просто имай малко търпение. :)
--- Край на цитат ---
Па ако знаеш в други социални медии що постове имам - не е истина :)
Първия тест в реални условия и калибриране по чисто нови маркови манометри на чисто нова инсталация, на които мога да имам вяра.
Вече е и в кутийка, подходящ за носене.
EDM electronics:
Чудя се за 60 г. това ли ти е единствения самостоятелен проект?
Много корекомски ми изглежда, особено съпунерката. :D
Явно от много Сименси и Нитачита си придобил чувство за "естетика и добър външен вид".
Понеже го раздаваше даскал със самочувствието на голям програмист, ми е странно как може да се хвалиш с проекти в които логиката на програмата се състои от два реда. Понеже датчика ти е аналогов имаш само една ардуиновска функция val = analogRead(Pin_X); и втория ред е да притниш тази променлива във функцията на дисплея. А иначе за дисплея си ползвал готова ардуиновска библиотека.
Дори си мисля, че не си сложил и и функция на един прост НЧ-филтър на променливата, да не ти трепери стойността на дисплея.
Това ли успя на измислиш за 60 г., тази "сложнотия" ли?
С 23 000 поста в технически форуми и сигурно над 100 000 във фейсбук, този резултат ли ти донесоха? :)
juliang:
Да виждаш и ред програмен код? :)
--- Цитат на: EDM electronics в Март 09, 2023, 02:27:17 pm ---Дори си мисля, че не си сложил и и функция на един прост НЧ-филтър на променливата, да не ти трепери стойността на дисплея.
--- Край на цитат ---
И това ми го казва човек, на който дни наред му обяснявам що е то PID контролер? :) Споко, всичко си има, не преживявай.
А като стигнеш ниво на сложност на логиката като това:
Или поне като това:
тогаз може и да се вслушам в думите ти. Дотогава само бръмчиш като ВЕФ на средни вълни :)
P.S. Ей така сме ние, с оловните обувки и със сажди до лактите:
Да не говорим, че младоци кат теб през живота си не са виждали, какво остава да са писали такъв код:
--- Код: --- LIST p=16F886 ; PIC16F886 is the target processor
Processor 16F886
Include "p16F886.inc"
radix dec
errorlevel -302
__CONFIG _CONFIG1, _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _LVP_OFF
__CONFIG _CONFIG2, _WRT_OFF & _BOR21V
; FLGS description:
; BIT MEAN
; 0 - Key is still pressed, but action is taken
; 1 - Adaptive/constant motor speed
; 2 - Fast motor motion
; 3 - Auto/Manual
; 4 - Fully opened valve
CBLOCK 0X20 ;start of internal memory
COUNTER0, COUNTER1, I, STR_LEN, ROW1, ROW2, SENS_COUNT, MENU_PAGE
COIL_CUR_POS, DELAY_ON, DELAY_OFF, FLGS, MOTOR_POS, LAMBDA_LO, LAMBDA_HI,LAMBDA, LAMBDA_MAX
ENDC
CBLOCK 0x70
TEMP
ENDC
org 0x2100
de 0x12, 0x0A, 0x0A, 0x14
line1 equ 128+0 ; LCD "line 1" command
line2 equ 128+64 ; LCD "line 2" command
org 0x00
goto START
nop
nop
MOTOR_TABLE
ADDWF PCL,F
RETLW B'00110000'
RETLW B'00100000'
RETLW B'01100000'
RETLW B'01000000'
RETLW B'11000000'
RETLW B'10000000'
RETLW B'10010000'
RETLW B'00010000'
AUTO_STR
ADDWF PCL,F
DT "AUTO ",00H
MANUAL_STR
ADDWF PCL,F
DT "MANUAL ",00H
REWIND_STR
ADDWF PCL,F
DT "REWIND ",00H
OK_STR
ADDWF PCL,F
DT "OK:",00H
HI_STR
ADDWF PCL,F
DT "HI:",00H
LO_STR
ADDWF PCL,F
DT "LO:",00H
SAVE_STR
ADDWF PCL,F
DT "SAVE?",00H
YN_STR
ADDWF PCL,F
DT "YES",0xD9," NO",0xDA
DLY_STR
ADDWF PCL,F
DT "DELAY",00H
LAMBDA_STR
ADDWF PCL,F
DT "LAMBDA",00H
MOTOR_STR
ADDWF PCL,F
DT "MOTOR ST",00H
HALF_STR
ADDWF PCL,F
DT "EP:ADAPT",00H
FULL_STR
ADDWF PCL,F
DT "EP:CONST",00H
ON_STR
ADDWF PCL,F
DT "ON: ",00H
OFF_STR
ADDWF PCL,F
DT "OFF: ",00H
DISCARD_STR
ADDWF PCL,F
DT "DISCARD",00H
; *** Start of program code ***
START
BANKSEL PORTA ; Bank 0
CLRF PORTA ; Init PORTA
CLRF PORTB ; Init PORTB
CLRF PORTC ; Init PORTC
BANKSEL TRISA ; Bank 1
CLRF TRISA ; All PORTA as output
BSF TRISA,0 ; RA0 as input
CLRF TRISC ; PORTC as output
MOVLW B'11100000'
MOVWF TRISB ; RB <7:5> as input
BCF OPTION_REG, 7 ; Enable PORTB pull-up resostors
MOVLW b'00000000'
MOVWF ADCON1
BANKSEL ANSEL ; Bank 3
CLRF ANSEL ; digital I/O
BSF ANSEL,0 ; RA0 as analog input
CLRF ANSELH ; digital I/O
BANKSEL PORTA ; Bank 0
MOVLW b'11000001'
MOVWF ADCON0
MOVLW .255 ; Init LCD
CALL DELAY_100_US
MOVLW 0x30
CALL PutNyb
MOVLW .4
CALL DELAY_10_US
MOVLW 0x20
CALL PutNyb
MOVLW .4
CALL DELAY_10_US
MOVLW b'00101000' ; 4-bit, 2-lines, 5x7 font
CALL PutCMD
movlw b'00001100' ; display, cursor, blink all off
CALL PutCMD
MOVLW b'00000001' ; clear display (1.53-msecs)
call PutCMD ; send "entry mode set" command
MOVLW .16
CALL DELAY_100_US
movlw b'00000110' ; cursor inc, shift off
call PutCMD ; send "entry mode set" command
MOVLW line1 ; Print "REWIND" on display
CALL PutCMD
CLRF STR_LEN
MOVF STR_LEN,W
CALL REWIND_STR
ADDLW .0
BTFSC STATUS,Z
GOTO $+4
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
MOVLW 0 ; EEPROM Address for DELAY_ON
CALL READ_EEPROM
MOVWF DELAY_ON
MOVLW 1 ; EEPROM Address for DELAY_OFF
CALL READ_EEPROM
MOVWF DELAY_OFF
MOVLW 2 ; EEPROM Address for DELAY_OFF
CALL READ_EEPROM
MOVWF LAMBDA_LO
MOVLW 3 ; EEPROM Address for DELAY_OFF
CALL READ_EEPROM
MOVWF LAMBDA_HI
CLRF FLGS ; clear all flags
CLRF COIL_CUR_POS ; set initial motor position
MOVLW .10
MOVWF SENS_COUNT
MOVLW .40
MOVWF LAMBDA_MAX
MOVLW .0
MOVWF MENU_PAGE
MOVLW .255 ; set initial motor position
MOVWF TEMP
MOVWF MOTOR_POS
CALL R_OPEN
DECF TEMP,F
BTFSS STATUS,Z
GOTO $-3
MOVLW .255
MOVWF TEMP
MOVWF MOTOR_POS
CALL R_OPEN
DECF TEMP,F
BTFSS STATUS,Z
GOTO $-3
CLRF MOTOR_POS
BCF FLGS,4
CALL LCD_AUTO
MAIN CLRWDT ; Clear Watchdog timer
CALL CHK_KEYPAD
MOVF ROW1,F ; Check if Row1=0 (no key pressed)
BTFSC STATUS,Z ; Any key on ROW1 pressed?
BCF FLGS,0
MOVF MENU_PAGE,W
MOVWF I
BTFSC STATUS,Z ; Menu is on page 0 (Auto)?
GOTO PAGE_0 ; Yes
DECF I,F
BTFSC STATUS,Z ; Menu is on page 1 (Manual)?
GOTO PAGE_1 ; Yes
DECF I,F
BTFSC STATUS,Z ; Menu is on page 2 (Lambda_LO)?
GOTO PAGE_2 ; Yes
DECF I,F
BTFSC STATUS,Z ; Menu is on page 3 (Lambda_HI)?
GOTO PAGE_3 ; Yes
DECF I,F
BTFSC STATUS,Z ; Menu is on page 4 (Motor step)?
GOTO PAGE_4 ; Yes
DECF I,F
BTFSC STATUS,Z ; Menu is on page 5 (DELAY ON)?
GOTO PAGE_5 ; Yes
DECF I,F
BTFSC STATUS,Z ; Menu is on page 6 (DELAY_OFF)?
GOTO PAGE_6 ; Yes
DECF I,F
BTFSC STATUS,Z ; Menu is on page 7 (SAVE)?
GOTO PAGE_7 ; Yes
SLEEP ; There is no more pages. If program goes here there is some wrong with code :)
PAGE_0
CALL LCD_LAMBDA
BTFSC FLGS,0 ; Key is still pressed, but taken, so
GOTO AUTO ; nothing to do
BTFSS ROW1,0 ; Pressed key "1" (AUTO/MANUAL)?
GOTO AUTO ; No, no key is pressed or pressed other key
BSF FLGS,0 ; Yes, key "1" is pressed - switch to manual
BSF FLGS,3 ; Manual mode (is this FLGS,3 really needed?)
MOVLW 0x01 ; Clear display
CALL PutCMD
MOVLW .16
CALL DELAY_100_US
CLRF STR_LEN
MOVF STR_LEN,W
CALL MANUAL_STR
ADDLW .0
BTFSC STATUS,Z
GOTO $+4
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
INCF MENU_PAGE,F
GOTO MAIN
AUTO
MOVF LAMBDA_LO,W
SUBWF LAMBDA,W
BTFSC STATUS,C ; Lambda is high then LAMBDA_LO?
GOTO NOT_LO ; Yes
DECFSZ SENS_COUNT,F ; No - lambda is low. Counter = 0?
GOTO MAIN ; No - next measurement
CALL LCD_LO ; Yes - counter expired, lambda is still low, it's time to open valve
BCF PORTB,4 ; Test LED off
BCF FLGS,2 ; Set slow motor speed
BTFSS FLGS,1
GOTO A1
MOVF DELAY_OFF,W
MOVWF SENS_COUNT
GOTO A2
A1 RLF LAMBDA,W
MOVWF SENS_COUNT
INCF SENS_COUNT,F
MOVF LAMBDA,F ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
BTFSC STATUS,Z ; LAMBDA is 0?
BSF FLGS,2 ; Yes - turn motor on "full throttle"
DECFSZ LAMBDA,W ; LAMBDA = 1 (to ignore measure bouncing)?
BSF FLGS,2 ; Yes - turn motor on "full throttle"
A2 CALL R_OPEN ; Rotate motor CW
GOTO MAIN ; Motor is rotated one step, goto main
NOT_LO MOVF LAMBDA_HI,W
SUBWF LAMBDA,W
BTFSC STATUS,C ; Lambda is high then LAMBDA_HI?
GOTO IS_HI ; Yes
MOVLW line2 ; No, lambda is in range.
CALL PutCMD ; Print "OK" on display
CLRF STR_LEN
MOVF STR_LEN,W
CALL OK_STR
ADDLW .0
BTFSC STATUS,Z
GOTO $+4
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
MOVLW .10
MOVWF SENS_COUNT
GOTO MAIN ; Lambda is in range LAMBDA_LO - LAMBDA_HI. Nothing to do, next measurement cycle
IS_HI DECFSZ SENS_COUNT,F ; Lambda is high. Counter = 0?
GOTO MAIN ; No - next measurement
CALL LCD_HI ; Yes - counter expired, lambda is still high.
BSF PORTB,4 ; Test LED
BCF FLGS,2 ; Set slow motor speed
BTFSS FLGS,1
GOTO A11
MOVF DELAY_OFF,W
MOVWF SENS_COUNT
GOTO A21
A11 MOVF LAMBDA,W ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
SUBWF LAMBDA_MAX,W
BTFSC STATUS,Z ; Lambda = lambda_max?
BSF FLGS,2 ; Yes - set fast motor speed
MOVWF SENS_COUNT ; Store counter value
DECF SENS_COUNT,W
BTFSC STATUS,Z ; Lambda = lambda_max-1 (to ignore measure bouncing) ?
BSF FLGS,2 ; Yes - set fast motor speed
RLF SENS_COUNT,F
INCF SENS_COUNT,F
A21 CALL R_CLOSE ; Rotace motor CCW
GOTO MAIN ; Motor is rotated one step, goto main
PAGE_1
CALL LCD_LAMBDA
BTFSC FLGS,0 ; Key is still pressed, but taken, so
GOTO MAIN ; nothing to do
BTFSC ROW1,0 ; Pressed key "1" (AUTO/MANUAL)?
GOTO TO_AUTO ; Yes, key "1" is pressed - switch back to auto
BTFSS ROW1,1 ; Pressed key "2"?
GOTO J1_1 ; No - check other keys
BSF FLGS,0
CALL LCD_LMBTXT
CALL LCD_LO
MOVF LAMBDA_LO,W
CALL PutDEC
INCF MENU_PAGE,F
GOTO MAIN
J1_1 BTFSS ROW1,2 ; Pressed key "3"?
GOTO J1_3 ; No - check other keys
MOVLW line1+7 ; Key "3" is pressed. Print up arrow on display
CALL PutCMD
MOVLW 0xD9
CALL PutDAT
BSF FLGS,2
BCF FLGS,4 ; Turn off valve limiter
CALL R_OPEN
GOTO MAIN
J1_3 BTFSC ROW1,5 ; Pressed key "6"?
GOTO J1_4
MOVLW line1+7 ; No - clear arrows
CALL PutCMD
MOVLW ' '
CALL PutDAT
GOTO MAIN ; No, other key is pressed, return to main
J1_4 MOVLW line1+7 ; Key "6" is pressed. Print down arrow on display
CALL PutCMD
MOVLW 0xDA
CALL PutDAT
BSF FLGS,2
CALL R_CLOSE
GOTO MAIN
TO_AUTO
BSF FLGS,0
BCF FLGS,3
BCF FLGS,4
MOVLW .255
MOVWF MOTOR_POS
CALL LCD_AUTO
CLRF MENU_PAGE
GOTO MAIN
PAGE_2
BTFSC FLGS,0 ; Key is still pressed, but taken, so
GOTO MAIN ; nothing to do
BTFSC ROW1,0 ; Pressed key "1" (AUTO/MANUAL)?
GOTO TO_AUTO ; Yes, key "1" is pressed - switch back to auto
BTFSS ROW1,1 ; Pressed key "2"?
GOTO J2_1 ; No - check other keys
BSF FLGS,0
CALL LCD_HI
MOVF LAMBDA_HI,W
CALL PutDEC
INCF MENU_PAGE,F
GOTO MAIN
J2_1 BTFSS ROW1,2 ; Pressed key "3"?
GOTO J2_3 ; No - check other keys
BSF FLGS,0
INCF LAMBDA_LO,F
MOVF LAMBDA_LO,W
CALL PutDEC
GOTO MAIN
J2_3 BTFSS ROW1,5 ; Pressed key "6"?
GOTO MAIN ; No, other key is pressed, return to main
BSF FLGS,0
DECF LAMBDA_LO,F
MOVF LAMBDA_LO,W
CALL PutDEC
GOTO MAIN
PAGE_3
BTFSC FLGS,0 ; Key is still pressed, but taken, so
GOTO MAIN ; nothing to do
BTFSC ROW1,0 ; Pressed key "1" (AUTO/MANUAL)?
GOTO TO_AUTO ; Yes, key "1" is pressed - switch back to auto
BTFSS ROW1,1 ; Pressed key "2"?
GOTO J3_1 ; No - check other keys
BSF FLGS,0
CALL LCD_MOTOR
BTFSS FLGS,1
GOTO $+3
CALL LCD_FULL
GOTO $+2
CALL LCD_HALF
INCF MENU_PAGE,F
GOTO MAIN
J3_1 BTFSS ROW1,2 ; Pressed key "3"?
GOTO J3_3 ; No - check other keys
BSF FLGS,0
INCF LAMBDA_HI,F
MOVF LAMBDA_HI,W
CALL PutDEC
GOTO MAIN
J3_3 BTFSS ROW1,5 ; Pressed key "6"?
GOTO MAIN ; No, other key is pressed, return to main
BSF FLGS,0
DECF LAMBDA_HI,F
MOVF LAMBDA_HI,W
CALL PutDEC
GOTO MAIN
PAGE_4
BTFSC FLGS,0 ; Key is still pressed, but taken, so
GOTO MAIN ; nothing to do
BTFSC ROW1,0 ; Pressed key "1" (AUTO/MANUAL)?
GOTO TO_AUTO ; Yes, key "1" is pressed - switch back to auto
BTFSS ROW1,1 ; Pressed key "2"?
GOTO J4_1 ; No - check other keys
BSF FLGS,0
CALL LCD_DELAY
MOVLW line2
CALL PutCMD
CLRF STR_LEN
MOVF STR_LEN,W
CALL ON_STR
ADDLW .0
BTFSC STATUS,Z
GOTO $+4
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
INCF MENU_PAGE,F
MOVLW line2+4
CALL PutCMD
MOVF DELAY_ON,W
CALL PutDIG
GOTO MAIN
J4_1 BTFSS ROW1,2 ; Pressed key "3"?
GOTO J4_3 ; No - check other keys
BSF FLGS,0
BSF FLGS,1
CALL LCD_FULL
GOTO MAIN
J4_3 BTFSS ROW1,5 ; Pressed key "6"?
GOTO MAIN ; No, other key is pressed, return to main
BSF FLGS,0
BCF FLGS,1
CALL LCD_HALF
GOTO MAIN
PAGE_5
BTFSC FLGS,0 ; Key is still pressed, but taken, so
GOTO MAIN ; nothing to do
BTFSC ROW1,0 ; Pressed key "1" (AUTO/MANUAL)?
GOTO TO_AUTO ; Yes, key "1" is pressed - switch back to auto
BTFSS ROW1,1 ; Pressed key "2"?
GOTO J5_1 ; No - check other keys
BSF FLGS,0
CALL LCD_DELAY
MOVLW line2
CALL PutCMD
CLRF STR_LEN
MOVF STR_LEN,W
CALL OFF_STR
ADDLW .0
BTFSC STATUS,Z
GOTO $+4
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
INCF MENU_PAGE,F
MOVLW line2+4
CALL PutCMD
MOVF DELAY_OFF,W
CALL PutDIG
GOTO MAIN
J5_1 BTFSS ROW1,2 ; Pressed key "3"?
GOTO J5_3 ; No - check other keys
BSF FLGS,0
INCF DELAY_ON,F
MOVLW line2+4
CALL PutCMD
MOVF DELAY_ON,W
CALL PutDIG
GOTO MAIN
J5_3 BTFSS ROW1,5 ; Pressed key "6"?
GOTO MAIN ; No, other key is pressed, return to main
BSF FLGS,0
DECF DELAY_ON,F
MOVLW line2+4
CALL PutCMD
MOVF DELAY_ON,W
CALL PutDIG
GOTO MAIN
PAGE_6
BTFSC FLGS,0 ; Key is still pressed, but taken, so
GOTO MAIN ; nothing to do
BTFSC ROW1,0 ; Pressed key "1" (AUTO/MANUAL)?
GOTO TO_AUTO ; Yes, key "1" is pressed - switch back to auto
BTFSS ROW1,1 ; Pressed key "2"?
GOTO J6_1 ; No - check other keys
BSF FLGS,0
CALL LCD_SAVE
CALL LCD_YN
INCF MENU_PAGE,F
GOTO MAIN
J6_1 BTFSS ROW1,2 ; Pressed key "3"?
GOTO J6_3 ; No - check other keys
BSF FLGS,0
INCF DELAY_OFF,F
MOVLW line2+4
CALL PutCMD
MOVF DELAY_OFF,W
CALL PutDIG
GOTO MAIN
J6_3 BTFSS ROW1,5 ; Pressed key "6"?
GOTO MAIN ; No, other key is pressed, return to main
BSF FLGS,0
DECF DELAY_OFF,F
MOVLW line2+4
CALL PutCMD
MOVF DELAY_OFF,W
CALL PutDIG
GOTO MAIN
PAGE_7
BTFSC FLGS,0 ; Key is still pressed, but taken, so
GOTO MAIN ; nothing to do
BTFSC ROW1,0 ; Pressed key "1" (AUTO/MANUAL)?
GOTO TO_AUTO ; Yes, key "1" is pressed - switch back to auto
BTFSS ROW1,2 ; Pressed key "3"?
GOTO J7_1 ; No - check others
BSF FLGS,0 ; Key "3" is pressed
MOVF DELAY_ON,W
MOVWF TEMP
MOVLW .0
CALL SAVE_EEPROM
MOVF DELAY_OFF,W
MOVWF TEMP
MOVLW .1
CALL SAVE_EEPROM
MOVF LAMBDA_LO,W
MOVWF TEMP
MOVLW .2
CALL SAVE_EEPROM
MOVF LAMBDA_HI,W
MOVWF TEMP
MOVLW .3
CALL SAVE_EEPROM
CALL LCD_SAVE
MOVLW line1+4
CALL PutCMD
MOVLW 'D'
CALL PutDAT
MOVLW .255
CALL DELAY_10_MS
GOTO TO_AUTO
J7_1 BTFSS ROW1,5 ; Pressed key "6"?
GOTO MAIN ; No, other key is pressed, return to main
BSF FLGS,0
CALL LCD_DISCARD
MOVLW .255
CALL DELAY_10_MS
GOTO TO_AUTO
CHK_KEYPAD
CLRF ROW1
CLRF ROW2
MOVLW B'00001110'
MOVWF PORTB
BTFSS PORTB,7
BSF ROW1,0
BTFSS PORTB,6
BSF ROW1,1
BTFSS PORTB,5
BSF ROW1,2
MOVLW B'00001101'
MOVWF PORTB
BTFSS PORTB,7
BSF ROW1,3
BTFSS PORTB,6
BSF ROW1,4
BTFSS PORTB,5
BSF ROW1,5
MOVLW B'00001011'
MOVWF PORTB
BTFSS PORTB,7
BSF ROW1,6
BTFSS PORTB,6
BSF ROW1,7
BTFSS PORTB,5
BSF ROW2,0
MOVLW B'00000111'
MOVWF PORTB
BTFSS PORTB,7
BSF ROW2,1
BTFSS PORTB,6
BSF ROW2,2
BTFSS PORTB,5
BSF ROW2,3
CLRF PORTB
RETURN
READ_EEPROM
BANKSEL EEADR
MOVWF EEADR
BANKSEL EECON1
BCF EECON1,EEPGD
BSF EECON1, RD
BANKSEL EEDAT
MOVF EEDAT,W
BANKSEL PORTA
RETURN
SAVE_EEPROM
BANKSEL EEADR
MOVWF EEADR ;Data Memory Address to write
MOVF TEMP,W
MOVWF EEDAT ;Data Memory Value to write
BANKSEL EECON1
BCF EECON1,EEPGD ;Point to DATA memory
BSF EECON1,WREN ;Enable writes
BCF INTCON,GIE ;Disable INTs.
BTFSC INTCON,GIE ;SEE AN576
GOTO $-2
MOVLW 0x55
MOVWF EECON2 ;Write 55h
MOVLW 0xAA
MOVWF EECON2 ;Write AAh
BSF EECON1,WR ;Set WR bit to begin write
BTFSC EECON1,WR
GOTO $-1
BSF INTCON,GIE ;Disable INTs.
BCF EECON1,WREN ;Disable writes
BANKSEL PORTA
RETURN
PutDIG MOVWF I
CLRF COUNTER0
MOVLW .100
INCF COUNTER0,F
SUBWF I,F
BTFSC STATUS,C
GOTO $-3
ADDWF I,F
DECF COUNTER0,W
ADDLW 0x30
CALL PutDAT
CLRF COUNTER0
MOVLW .10
INCF COUNTER0,F
SUBWF I,F
BTFSC STATUS,C
GOTO $-3
ADDWF I,F
DECF COUNTER0,W
ADDLW 0x30
CALL PutDAT
MOVF I,W
ADDLW 0x30
CALL PutDAT
RETURN
PutDEC MOVWF I
ADDWF I,F
MOVLW line2+3
CALL PutCMD
CLRF COUNTER0
MOVLW .100
INCF COUNTER0,F
SUBWF I,F
BTFSC STATUS,C
GOTO $-3
ADDWF I,F
DECF COUNTER0,W
ADDLW 0x30
CALL PutDAT
MOVLW '.'
CALL PutDAT
CLRF COUNTER0
MOVLW .10
INCF COUNTER0,F
SUBWF I,F
BTFSC STATUS,C
GOTO $-3
ADDWF I,F
DECF COUNTER0,W
ADDLW 0x30
CALL PutDAT
MOVF I,W
ADDLW 0x30
CALL PutDAT
MOVLW 'V'
CALL PutDAT
; MOVLW line1+6 ; TEST ONLY!!!!!!!!!!!!!!!
; CALL PutCMD
; MOVF FLGS,W
; CALL PutDIG
; MOVLW ' '
; CALL PutDAT
; MOVF MOTOR_POS,W
; CALL PutDIG
;
RETURN
PutCMD ; entry point for "cmd" data
clrc ; RS = 0 (command)
skpnc
PutDAT ; entry point for "dat" data
setc ; RS = 1 (data)
MOVWF TEMP ; save WREG data byte
CALL PutNyb ; send left nybble
SWAPF TEMP,W ; hi nybble in b3..b0
CALL PutNyb ; send right nybble
MOVLW 4
CALL DELAY_10_US
return
PutNyb
ANDLW 0xF0 ; mask off left nybble
IORLW b'00001000' ; set lcd RS bit (RB3)
skpc ; C=1 (RS=1)? yes, skip, else
XORLW b'00001000' ; clr lcd RS bit (RB3)
MOVWF PORTA ; assert D7..D4 & RS pins
IORLW b'00000100' ; set lcd E bit (RB2)
MOVWF PORTA ; E = 1 (strobe)
XORLW b'00000100' ; clr lcd E bit (RB2)
NOP
MOVWF PORTA ; E = 0
return
R_CLOSE ; rotate motor one step in closing position
CALL DO_STEP
BCF FLGS,4
BTFSC COIL_CUR_POS,0
GOTO C1
BTFSC FLGS,2
INCF COIL_CUR_POS,F
C1 INCF COIL_CUR_POS,F
BTFSS COIL_CUR_POS,3
RETURN
CLRF COIL_CUR_POS
INCF MOTOR_POS,F
RETURN
R_OPEN ; rotate motor one step in opening position
BTFSS FLGS,4
GOTO C3
MOVF MOTOR_POS,F
BTFSC STATUS,Z
RETURN
C3 CALL DO_STEP
BTFSC COIL_CUR_POS,0
GOTO C2
BTFSC FLGS,2
DECF COIL_CUR_POS,F
C2 DECF COIL_CUR_POS,F
BTFSS COIL_CUR_POS,7
RETURN
MOVF MOTOR_POS,F
BTFSC STATUS,Z
BSF FLGS,4
DECF MOTOR_POS,F
MOVLW .7
MOVWF COIL_CUR_POS
BTFSC FLGS,2
DECF COIL_CUR_POS,F
RETURN
DO_STEP ; common part of code for two previous subs (must save the code space :) )
MOVF COIL_CUR_POS,W
CALL MOTOR_TABLE
MOVWF PORTC
MOVF DELAY_ON,W
CALL DELAY_100_US
CLRF PORTC
MOVF DELAY_OFF,W
BTFSS STATUS,Z
CALL DELAY_100_US
RETURN
MAN_AUTO ; Manual or auto?
BSF FLGS,0
BTFSS FLGS,3
GOTO MANUAL
MOVLW .10 ; Automatic mode
MOVWF SENS_COUNT
MOVLW .7
MOVWF MENU_PAGE
BCF FLGS,3
GOTO LCD_AUTO
MANUAL BSF FLGS,3 ; Manual mode
MOVLW line1
CALL PutCMD
CLRF STR_LEN
MOVF STR_LEN,W
CALL MANUAL_STR
ADDLW .0
BTFSC STATUS,Z
RETURN
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
LCD_AUTO
MOVLW 0x01 ; Clear display
CALL PutCMD
MOVLW .16
CALL DELAY_100_US
MOVLW line1 ; Print "AUTO" on display
CALL PutCMD
CLRF STR_LEN
MOVF STR_LEN,W
CALL AUTO_STR
ADDLW .0
BTFSC STATUS,Z
RETURN
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
LCD_SAVE
MOVLW 0x01 ; Clear display
CALL PutCMD
MOVLW .16
CALL DELAY_100_US
MOVLW line1 ; Print "AUTO" on display
CALL PutCMD
CLRF STR_LEN
MOVF STR_LEN,W
CALL SAVE_STR
ADDLW .0
BTFSC STATUS,Z
RETURN
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
LCD_DELAY
MOVLW 0x01 ; Clear display
CALL PutCMD
MOVLW .16
CALL DELAY_100_US
MOVLW line1 ; Print "AUTO" on display
CALL PutCMD
CLRF STR_LEN
MOVF STR_LEN,W
CALL DLY_STR
ADDLW .0
BTFSC STATUS,Z
RETURN
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
LCD_LMBTXT
MOVLW 0x01 ; Clear display
CALL PutCMD
MOVLW .16
CALL DELAY_100_US
MOVLW line1 ; Print "AUTO" on display
CALL PutCMD
CLRF STR_LEN
MOVF STR_LEN,W
CALL LAMBDA_STR
ADDLW .0
BTFSC STATUS,Z
RETURN
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
LCD_MOTOR
MOVLW 0x01 ; Clear display
CALL PutCMD
MOVLW .16
CALL DELAY_100_US
MOVLW line1 ; Print "AUTO" on display
CALL PutCMD
CLRF STR_LEN
MOVF STR_LEN,W
CALL MOTOR_STR
ADDLW .0
BTFSC STATUS,Z
RETURN
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
LCD_DISCARD
MOVLW 0x01 ; Clear display
CALL PutCMD
MOVLW .16
CALL DELAY_100_US
MOVLW line1 ; Print "AUTO" on display
CALL PutCMD
CLRF STR_LEN
MOVF STR_LEN,W
CALL DISCARD_STR
ADDLW .0
BTFSC STATUS,Z
RETURN
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
LCD_HALF
MOVLW line2
CALL PutCMD
CLRF STR_LEN
MOVF STR_LEN,W
CALL HALF_STR
ADDLW .0
BTFSC STATUS,Z
RETURN
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
LCD_FULL
MOVLW line2
CALL PutCMD
CLRF STR_LEN
MOVF STR_LEN,W
CALL FULL_STR
ADDLW .0
BTFSC STATUS,Z
RETURN
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
LCD_LO
MOVLW line2
CALL PutCMD
CLRF STR_LEN
MOVF STR_LEN,W
CALL LO_STR
ADDLW .0
BTFSC STATUS,Z
RETURN
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
LCD_HI
MOVLW line2
CALL PutCMD
CLRF STR_LEN
MOVF STR_LEN,W
CALL HI_STR
ADDLW .0
BTFSC STATUS,Z
RETURN
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
LCD_YN
MOVLW line2
CALL PutCMD
CLRF STR_LEN
MOVF STR_LEN,W
CALL YN_STR
ADDLW .0
BTFSC STATUS,Z
RETURN
CALL PutDAT
INCF STR_LEN,F
GOTO $-7
LCD_LAMBDA ; Get lambda value and print it on display
BSF ADCON0,GO
BTFSC ADCON0,GO
GOTO $-1
MOVF ADRESH,W
MOVWF LAMBDA
CALL PutDEC
MOVF LAMBDA,W
SUBWF LAMBDA_MAX,W
BTFSC STATUS,C
RETURN
MOVF LAMBDA,W
MOVWF LAMBDA_MAX
RETURN
INC_ON
BSF FLGS,0
INCF DELAY_ON,F
MOVLW line2
CALL PutCMD
MOVF DELAY_ON,W
CALL PutDIG
RETURN
DEC_ON
BSF FLGS,0
BTFSS STATUS,2
DECF DELAY_ON,F
MOVLW line2
CALL PutCMD
MOVF DELAY_ON,W
CALL PutDIG
MOVF DELAY_ON,F
RETURN
INC_OFF
BSF FLGS,0
INCF DELAY_OFF,F
MOVLW line2+4
CALL PutCMD
MOVF DELAY_OFF,W
CALL PutDIG
RETURN
DEC_OFF
BSF FLGS,0
BTFSS STATUS,2
DECF DELAY_OFF,F
MOVLW line2+4
CALL PutCMD
MOVF DELAY_OFF,W
CALL PutDIG
MOVF DELAY_OFF,F
RETURN
DELAY_10_MS ;dealy (W * 10 ms)
movwf COUNTER0
INCF COUNTER0,F
movlw .248
movwf COUNTER1
nop
nop
nop
nop
nop
nop
decfsz COUNTER1,F
goto $-7
decfsz COUNTER0,F
goto $-11
return
DELAY_100_US ;dealy (W * 0.1 ms)
movwf COUNTER0 ;move w register into COUNTER0
INCF COUNTER0,F
movlw .25 ;inner part of delay loop equal to 0.1 millisecond by moving 25 into w register
movwf COUNTER1 ;move w register into COUNTER1
nop ;no operation
decfsz COUNTER1,F ;decrement counter1 by 1
goto $-2
decfsz COUNTER0,F ;decrement counter 0 by 1
goto $-6 ;goto floop
return ;return
DELAY_10_US ;delay (W * 10 us)
MOVWF COUNTER1 ;move w register into COUNTER1
NOP ;no operation
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ COUNTER1,f ;decrement counter1 by 1
GOTO $-8
return
END ;end of program
--- Край на кода ---
EDM electronics:
По всичко ти личи, че никога не си се занимавал с електроника и не си проектирал нито едно устройство. Нямаш направена нито една платка. Гледам занимаваш се с графично програмиране, което общо взето е развойна среда на производител на конкретна арпаратура. Това за мен не е програмиране, направено е за папагали, за хора които не разбират от програмиране.
А контролера който ползваш е само с 8 kB флаш - по-слаба изчислителна мощ на 8-битов е трудно да намериш. Това е контролер детска играчка. Подобни се ползват в съдомиални и перални. Ардуиното е 3 пъти по-мощно.
Та младока се занимава само с STM32 32-битови контролери с Кортекс ядро или двуядрени - които за теб са тера инкогнита. Имам безброй проекти - собствени, библиотеки на много сложни датчици, като GPS, компаси, цифрови SPI термосензори с термодвойки и т.н. Няма контролер на STM32, който да не мога да програмирам от раз, каквото и да било.
Да ми показваш код с който конфигурираш някакъв регистър, като сложност - е не на мен тия...
Това да не си проектирал една платка през живота си е все едно емигрирал селянин да говори за "градски начин на живот" и сп. Плейбой. :D
Нали знаеш, че изхвърлячите много ги обичам и надушвам отдалече. :)
Навигация
[0] Списък на темите
Премини на пълна версия