Re: PIC16F886 lookup tables
Postat: 26 maj 2009, 01:17:43
Hehe nu vet jag hur jag såg fel!
Tolkade tabellen helt fel och trodde det som var decimaltalen var tecknet... Menmen nu förstår jag! 


Svenskt forum för elektroniksnack.
https://elektronikforumet.com/forum/
Kod: Markera allt
; *** Clock ***
clock
incf s1
call check_sec
call check_min
return
check_sec
movfw s1
sublw d'10'
btfsc STATUS,Z
goto check_sec_2
return
check_sec_2
movfw s2
sublw d'5'
btfsc STATUS,Z
goto inc_m1
clrf s1
incf s2
return
inc_m1
clrf s1
clrf s2
incf m1
return
check_min
movfw m1
sublw d'10'
btfsc STATUS,Z
goto inc_m2
return
inc_m2
incf m2
clrf m1
return
Eller bara 'x'.sodjan skrev:så är det enklare att använda a'x'
Kod: Markera allt
Bit 0 = 0.00 V = 10 kPa
Bit 1 = 0.02 V = 11 kPa
Bit 2 = 0.04 V = 12 kPa
Bit 3 = 0.06 V = 13 kPa
Bit 4 = 0.08 V = 14 kPa
Bit 5 = 0.10 V = 15 kPa
Bit 6 = 0.12 V = 16 kPa
Bit 7 = 0.14 V = 17 kPa
Bit 8 = 0.16 V = 18 kPa
Bit 9 = 0.18 V = 19 kPa
Bit 10 = 0.20 V = 20 kPa
Bit 11 = 0.22 V = 21 kPa
Bit 12 = 0.24 V = 22 kPa
Bit 13 = 0.25 V = 22 kPa
Bit 14 = 0.27 V = 23 kPa
Bit 15 = 0.29 V = 24 kPa
Bit 16 = 0.31 V = 25 kPa
Bit 17 = 0.33 V = 26 kPa
Bit 18 = 0.35 V = 27 kPa
Bit 19 = 0.37 V = 28 kPa
Bit 20 = 0.39 V = 29 kPa
Bit 21 = 0.41 V = 30 kPa
Bit 22 = 0.43 V = 31 kPa
Bit 23 = 0.45 V = 32 kPa
Bit 24 = 0.47 V = 33 kPa
Bit 25 = 0.49 V = 34 kPa
Bit 26 = 0.51 V = 35 kPa
Bit 27 = 0.53 V = 36 kPa
Bit 28 = 0.55 V = 37 kPa
Bit 29 = 0.57 V = 38 kPa
Bit 30 = 0.59 V = 39 kPa
Bit 31 = 0.61 V = 40 kPa
Bit 32 = 0.63 V = 41 kPa
Bit 33 = 0.65 V = 42 kPa
Bit 34 = 0.67 V = 43 kPa
Bit 35 = 0.69 V = 44 kPa
Bit 36 = 0.71 V = 45 kPa
Bit 37 = 0.73 V = 46 kPa
Bit 38 = 0.75 V = 47 kPa
Bit 39 = 0.76 V = 47 kPa
Bit 40 = 0.78 V = 48 kPa
Bit 41 = 0.80 V = 49 kPa
Bit 42 = 0.82 V = 50 kPa
Bit 43 = 0.84 V = 51 kPa
Bit 44 = 0.86 V = 52 kPa
Bit 45 = 0.88 V = 53 kPa
Bit 46 = 0.90 V = 54 kPa
Bit 47 = 0.92 V = 55 kPa
Bit 48 = 0.94 V = 56 kPa
Bit 49 = 0.96 V = 57 kPa
Bit 50 = 0.98 V = 58 kPa
Bit 51 = 1.00 V = 59 kPa
Bit 52 = 1.02 V = 60 kPa
Bit 53 = 1.04 V = 61 kPa
Bit 54 = 1.06 V = 62 kPa
Bit 55 = 1.08 V = 63 kPa
Bit 56 = 1.10 V = 64 kPa
Bit 57 = 1.12 V = 65 kPa
Bit 58 = 1.14 V = 66 kPa
Bit 59 = 1.16 V = 67 kPa
Bit 60 = 1.18 V = 68 kPa
Bit 61 = 1.20 V = 69 kPa
Bit 62 = 1.22 V = 70 kPa
Bit 63 = 1.24 V = 71 kPa
Bit 64 = 1.25 V = 72 kPa
Bit 65 = 1.27 V = 72 kPa
Bit 66 = 1.29 V = 73 kPa
Bit 67 = 1.31 V = 74 kPa
Bit 68 = 1.33 V = 75 kPa
Bit 69 = 1.35 V = 76 kPa
Bit 70 = 1.37 V = 77 kPa
Bit 71 = 1.39 V = 78 kPa
Bit 72 = 1.41 V = 79 kPa
Bit 73 = 1.43 V = 80 kPa
Bit 74 = 1.45 V = 81 kPa
Bit 75 = 1.47 V = 82 kPa
Bit 76 = 1.49 V = 83 kPa
Bit 77 = 1.51 V = 84 kPa
Bit 78 = 1.53 V = 85 kPa
Bit 79 = 1.55 V = 86 kPa
Bit 80 = 1.57 V = 87 kPa
Bit 81 = 1.59 V = 88 kPa
Bit 82 = 1.61 V = 89 kPa
Bit 83 = 1.63 V = 90 kPa
Bit 84 = 1.65 V = 91 kPa
Bit 85 = 1.67 V = 92 kPa
Bit 86 = 1.69 V = 93 kPa
Bit 87 = 1.71 V = 94 kPa
Bit 88 = 1.73 V = 95 kPa
Bit 89 = 1.75 V = 96 kPa
Bit 90 = 1.76 V = 97 kPa
Bit 91 = 1.78 V = 97 kPa
Bit 92 = 1.80 V = 98 kPa
Bit 93 = 1.82 V = 99 kPa
Bit 94 = 1.84 V = 100 kPa
Bit 95 = 1.86 V = 101 kPa
Bit 96 = 1.88 V = 102 kPa
Bit 97 = 1.90 V = 103 kPa
Bit 98 = 1.92 V = 104 kPa
Bit 99 = 1.94 V = 105 kPa
Bit 100 = 1.96 V = 106 kPa
Bit 101 = 1.98 V = 107 kPa
Bit 102 = 2.00 V = 108 kPa
Bit 103 = 2.02 V = 109 kPa
Bit 104 = 2.04 V = 110 kPa
Bit 105 = 2.06 V = 111 kPa
Bit 106 = 2.08 V = 112 kPa
Bit 107 = 2.10 V = 113 kPa
Bit 108 = 2.12 V = 114 kPa
Bit 109 = 2.14 V = 115 kPa
Bit 110 = 2.16 V = 116 kPa
Bit 111 = 2.18 V = 117 kPa
Bit 112 = 2.20 V = 118 kPa
Bit 113 = 2.22 V = 119 kPa
Bit 114 = 2.24 V = 120 kPa
Bit 115 = 2.25 V = 121 kPa
Bit 116 = 2.27 V = 121 kPa
Bit 117 = 2.29 V = 122 kPa
Bit 118 = 2.31 V = 123 kPa
Bit 119 = 2.33 V = 124 kPa
Bit 120 = 2.35 V = 125 kPa
Bit 121 = 2.37 V = 126 kPa
Bit 122 = 2.39 V = 127 kPa
Bit 123 = 2.41 V = 128 kPa
Bit 124 = 2.43 V = 129 kPa
Bit 125 = 2.45 V = 130 kPa
Bit 126 = 2.47 V = 131 kPa
Bit 127 = 2.49 V = 132 kPa
Bit 128 = 2.51 V = 133 kPa
Bit 129 = 2.53 V = 134 kPa
Bit 130 = 2.55 V = 135 kPa
Bit 131 = 2.57 V = 136 kPa
Bit 132 = 2.59 V = 137 kPa
Bit 133 = 2.61 V = 138 kPa
Bit 134 = 2.63 V = 139 kPa
Bit 135 = 2.65 V = 140 kPa
Bit 136 = 2.67 V = 141 kPa
Bit 137 = 2.69 V = 142 kPa
Bit 138 = 2.71 V = 143 kPa
Bit 139 = 2.73 V = 144 kPa
Bit 140 = 2.75 V = 145 kPa
Bit 141 = 2.76 V = 146 kPa
Bit 142 = 2.78 V = 146 kPa
Bit 143 = 2.80 V = 147 kPa
Bit 144 = 2.82 V = 148 kPa
Bit 145 = 2.84 V = 149 kPa
Bit 146 = 2.86 V = 150 kPa
Bit 147 = 2.88 V = 151 kPa
Bit 148 = 2.90 V = 152 kPa
Bit 149 = 2.92 V = 153 kPa
Bit 150 = 2.94 V = 154 kPa
Bit 151 = 2.96 V = 155 kPa
Bit 152 = 2.98 V = 156 kPa
Bit 153 = 3.00 V = 157 kPa
Bit 154 = 3.02 V = 158 kPa
Bit 155 = 3.04 V = 159 kPa
Bit 156 = 3.06 V = 160 kPa
Bit 157 = 3.08 V = 161 kPa
Bit 158 = 3.10 V = 162 kPa
Bit 159 = 3.12 V = 163 kPa
Bit 160 = 3.14 V = 164 kPa
Bit 161 = 3.16 V = 165 kPa
Bit 162 = 3.18 V = 166 kPa
Bit 163 = 3.20 V = 167 kPa
Bit 164 = 3.22 V = 168 kPa
Bit 165 = 3.24 V = 169 kPa
Bit 166 = 3.25 V = 170 kPa
Bit 167 = 3.27 V = 171 kPa
Bit 168 = 3.29 V = 171 kPa
Bit 169 = 3.31 V = 172 kPa
Bit 170 = 3.33 V = 173 kPa
Bit 171 = 3.35 V = 174 kPa
Bit 172 = 3.37 V = 175 kPa
Bit 173 = 3.39 V = 176 kPa
Bit 174 = 3.41 V = 177 kPa
Bit 175 = 3.43 V = 178 kPa
Bit 176 = 3.45 V = 179 kPa
Bit 177 = 3.47 V = 180 kPa
Bit 178 = 3.49 V = 181 kPa
Bit 179 = 3.51 V = 182 kPa
Bit 180 = 3.53 V = 183 kPa
Bit 181 = 3.55 V = 184 kPa
Bit 182 = 3.57 V = 185 kPa
Bit 183 = 3.59 V = 186 kPa
Bit 184 = 3.61 V = 187 kPa
Bit 185 = 3.63 V = 188 kPa
Bit 186 = 3.65 V = 189 kPa
Bit 187 = 3.67 V = 190 kPa
Bit 188 = 3.69 V = 191 kPa
Bit 189 = 3.71 V = 192 kPa
Bit 190 = 3.73 V = 193 kPa
Bit 191 = 3.75 V = 194 kPa
Bit 192 = 3.76 V = 195 kPa
Bit 193 = 3.78 V = 196 kPa
Bit 194 = 3.80 V = 196 kPa
Bit 195 = 3.82 V = 197 kPa
Bit 196 = 3.84 V = 198 kPa
Bit 197 = 3.86 V = 199 kPa
Bit 198 = 3.88 V = 200 kPa
Bit 199 = 3.90 V = 201 kPa
Bit 200 = 3.92 V = 202 kPa
Bit 201 = 3.94 V = 203 kPa
Bit 202 = 3.96 V = 204 kPa
Bit 203 = 3.98 V = 205 kPa
Bit 204 = 4.00 V = 206 kPa
Bit 205 = 4.02 V = 207 kPa
Bit 206 = 4.04 V = 208 kPa
Bit 207 = 4.06 V = 209 kPa
Bit 208 = 4.08 V = 210 kPa
Bit 209 = 4.10 V = 211 kPa
Bit 210 = 4.12 V = 212 kPa
Bit 211 = 4.14 V = 213 kPa
Bit 212 = 4.16 V = 214 kPa
Bit 213 = 4.18 V = 215 kPa
Bit 214 = 4.20 V = 216 kPa
Bit 215 = 4.22 V = 217 kPa
Bit 216 = 4.24 V = 218 kPa
Bit 217 = 4.25 V = 219 kPa
Bit 218 = 4.27 V = 220 kPa
Bit 219 = 4.29 V = 220 kPa
Bit 220 = 4.31 V = 221 kPa
Bit 221 = 4.33 V = 222 kPa
Bit 222 = 4.35 V = 223 kPa
Bit 223 = 4.37 V = 224 kPa
Bit 224 = 4.39 V = 225 kPa
Bit 225 = 4.41 V = 226 kPa
Bit 226 = 4.43 V = 227 kPa
Bit 227 = 4.45 V = 228 kPa
Bit 228 = 4.47 V = 229 kPa
Bit 229 = 4.49 V = 230 kPa
Bit 230 = 4.51 V = 231 kPa
Bit 231 = 4.53 V = 232 kPa
Bit 232 = 4.55 V = 233 kPa
Bit 233 = 4.57 V = 234 kPa
Bit 234 = 4.59 V = 235 kPa
Bit 235 = 4.61 V = 236 kPa
Bit 236 = 4.63 V = 237 kPa
Bit 237 = 4.65 V = 238 kPa
Bit 238 = 4.67 V = 239 kPa
Bit 239 = 4.69 V = 240 kPa
Bit 240 = 4.71 V = 241 kPa
Bit 241 = 4.73 V = 242 kPa
Bit 242 = 4.75 V = 243 kPa
Bit 243 = 4.76 V = 244 kPa
Bit 244 = 4.78 V = 245 kPa
Bit 245 = 4.80 V = 245 kPa
Bit 246 = 4.82 V = 246 kPa
Bit 247 = 4.84 V = 247 kPa
Bit 248 = 4.86 V = 248 kPa
Bit 249 = 4.88 V = 249 kPa
Bit 250 = 4.90 V = 250 kPa
Bit 251 = 4.92 V = 251 kPa
Bit 252 = 4.94 V = 252 kPa
Bit 253 = 4.96 V = 253 kPa
Bit 254 = 4.98 V = 254 kPa
Bit 255 = 5.00 V = 255 kPa
Det är en fördel att även läsa början på den meningen, då får man sammanhanget.sodjan skrev:Var det C som diskuterades ?
Och jag föredrar dessa: b'01010101', 123, 0xCE, 'M'. Andra personer föredrar nog något annat. Vissa vill ha tab-tecken i koden, andra vill ha space. Vissa vill ha tab-stops på 8, andra på 2. Osv.Jag föredrar skrivsetten :
b'01010101'
d'123' (inte .123)
h'CE' (inte CEh eller 0xCE)
a'M' (inte enbart 'M')
Vilket är ungefär samma sak som jag försöker säga...The MPASM assembler supports a clean and consistent method of specifying radix.
You are encouraged to develop using the radix and other directive methods described
within this document, even though certain older syntaxes may be supported for
compatibility reasons.
Kod: Markera allt
start
banksel ansel
movlw h'FF'
movwf ansel
clrf anselh
banksel trisa
movlw h'FF'
movwf trisa
clrf trisb
clrf trisc
;
banksel adcon1
clrf adcon1
banksel adcon0
movlw b'11000001'
movwf adcon0
;
banksel intcon
clrf intcon
banksel cm1con0
clrf cm1con0
banksel cm2con0
clrf cm2con0
banksel portb ; Change to bank 0
;
call lcd_init_hd44780 ; Setup LCD
; Set clock to 00:00
movlw b'00000000'
movwf m1
movwf m2
movwf s1
movwf s2
Kod: Markera allt
;
; Write to display...
;
write_lcd
call ADC
; *** Take care of TEMP_ADC value ***
movfw TEMP_ADC
movwf TEMP_RES
call TEMP_SPLIT
; *** Take care of PRESSURE_ADC value ***
movfw PRESSURE_ADC
;call METER_TABLE
movwf PRESSURE_M
movfw PRESSURE_ADC
movwf X
movlw d'246'
movwf Y
call mpy_F ; The result of X*Y is in locations H_byte & L_byte
movlw b'00001010' ; Add d'10' to result
addwf H_BYTE,W
movwf PRESSURE_RES
call PRESSURE_SPLIT
; *** Write "Tryck:" ***
movlw a'T'
call lcd_send_data
movlw a'r'
call lcd_send_data
movlw a'y'
call lcd_send_data
movlw a'c'
call lcd_send_data
movlw a'k'
call lcd_send_data
movlw a':'
call lcd_send_data
; *** Print pressure value ***
movfw PRESSURE_HNDS
call binary_convert
call lcd_send_data
movfw PRESSURE_TENS
call binary_convert
call lcd_send_data
movfw PRESSURE_ONES
call binary_convert
call lcd_send_data
; *** Write kPa ***
movlw a'k'
call lcd_send_data
movlw a'P'
call lcd_send_data
movlw a'a'
call lcd_send_data
; *** Move to position 0x0E
movlw b'10001110'
call lcd_send_cmd
; *** Print depth ***
movfw PRESSURE_M
call lcd_send_data
; *** Write "m" ***
movlw a'm'
call lcd_send_data
; *** Move to first character in secund row, position 0x40 ***
movlw b'11000000'
call lcd_send_cmd
; *** Write "Temp:" ***
movlw a'T'
call lcd_send_data
movlw a'e'
call lcd_send_data
movlw a'm'
call lcd_send_data
movlw a'p'
call lcd_send_data
movlw a':'
call lcd_send_data
; *** Print Temp value ***
movfw TEMP_TENS
call binary_convert
call lcd_send_data
movfw TEMP_ONES
call binary_convert
call lcd_send_data
; *** Write "C" ***
movlw b'01000011'
call lcd_send_data
; *** Move to left right part of lcd ***
movlw b'11001011'
call lcd_send_cmd
; *** Show clock ***
movfw m2 ; First minute number
call binary_convert
call lcd_send_data
movfw m1 ; Secund minute number
call binary_convert
call lcd_send_data
movlw b'00111010' ; :
call lcd_send_data
movfw s2 ; First second number
call binary_convert
call lcd_send_data
movfw s1 ; Second second number
call binary_convert
call lcd_send_data
call clock
call delay_lcd
call delay_lcd
call delay_lcd
call delay_lcd
call delay_lcd
movlw b'00000001' ; Clean screen
call lcd_send_cmd
goto write_lcd
;
; Multiply x*y and produce a 16bit result. The high byte of the
;result is aliased with x.
;
;*** Define a macro for adding & right shifting ***
;
mult MACRO bit ; Begin macro
btfsc X,bit
addwf H_byte,1
rrf H_byte,1
rrf L_byte,1
ENDM ; End of macro
; *** Begin Multiplier Routine ***
mpy_F
clrf H_byte
clrf L_byte
movf Y,W ; Move the multiplicand to W reg.
bcf STATUS,C ; Clear the carry bit in the status Reg.
mult 0
mult 1
mult 2
mult 3
mult 4
mult 5
mult 6
mult 7
;
retlw 0
PRESSURE_SPLIT
call GET_HNDS
movwf PRESSURE_HNDS
movfw PRESSURE_RES
call GET_TENS
movwf PRESSURE_TENS
movfw PRESSURE_RES
call GET_ONES
movwf PRESSURE_ONES
return
TEMP_SPLIT
call GET_HNDS
movwf TEMP_HNDS
movfw TEMP_RES
call GET_TENS
movwf TEMP_TENS
movfw TEMP_RES
call GET_ONES
movwf TEMP_ONES
return
;This routine will return the number of decimal
;hundreds from an 8-bit binary
;Input: w
;Output: w
;RAM:2
;Cycles: 12-24
GET_HNDS
movwf t1
clrf w2
get_hnds_loop
movlw .100
incf w2,f
subwf t1,f
btfsc STATUS,C
goto get_hnds_loop
decf w2,w
return
;This routine will return the number of decimal
;tens from an 8-bit binary
;Loop based, so it might take some time...
;It needs getones too
GET_TENS
movwf t1
clrf w2
get_tens_loop
movlw d'10'
incf w2,f
subwf t1,f
btfsc STATUS,C
goto get_tens_loop
decf w2,w
goto get_ones
GET_ONES
movwf w2
movlw d'10'
del_tens_loop
subwf w2,f
btfsc STATUS,C
goto del_tens_loop
addwf w2,w
return
Kod: Markera allt
;
; **********************************************
; **** Subrutins for ADC ****
; **********************************************
;
;{
ADC
call TEMP_START
call ADC_START
call TEMP_STORE
call PRESSURE_START
call ADC_START
call PRESSURE_STORE
TEMP_START
banksel ADCON0
bcf ADCON0,CHS0 ; Set AN0 on
call SampelTime ; Call delay
return
PRESSURE_START
banksel ADCON0
bsf ADCON0,CHS0 ; Set AN1 on
call SampelTime ; Call delay
return
ADC_START
bsf ADCON0,GO ; Start conversion
btfsc ADCON0,GO ; Is conversion done?
goto $-1 ; No, test again...
return
TEMP_STORE
banksel ADRESH
movf ADRESH,W ; Read upper 8 bits
movwf TEMP_ADC ; Store in TEMP_ADC (Don't care about the 2 low bits, only use 8 bits)
return
PRESSURE_STORE
banksel ADRESH
movf ADRESH,W ; Read upper 8 bits
movwf PRESSURE_ADC; Store in PRESSURE_ADC (Don't care about the 2 low bits, only use 8 bits)
return
SampelTime
call delay_5ms
call delay_5ms
call delay_5ms
call delay_5ms
call delay_5ms
call delay_5ms
call delay_5ms
call delay_5ms
call delay_5ms
call delay_5ms
return
;}
Titta på tabell 9-1 i databladet på sida 101. Du använder RC-klocka (FRC) till din ADC, vilket innebär att du ska titta på sista raden; Tad = 2-6µs således. Fotnot 1 säger: "The FRC source has a typical TAD time of 4 μs for VDD > 3.0V", men du kan använda 6 som Worst Case.Scorpiion skrev:Angående "aquisition time" så misstänkte jag att det kunde vara en felande faktor men tycker också att det är lite halv svårt att riktigt veta hur långt det ska vara,