Fits I.E. Medium and Large

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 11

: Fits i.e.

;medium and large

Index_ce: mov a,ce


Cjne a,#0h,ceno_0 ;chk for zero
Mov indx_ce,#3h ;middle
Ret
Ceno_0:
cjne a,#cerr_s,ceno_s :small error
cels_s: jb nce,cen_val ;chk for –ve error
mov ndx_ce,#4h ;
ret
cen_val mov indx_ce,#2h
cemor_s cjne a,#cerr_m,ceno_m ;medium error
cels_m jb nce,cen_vall ;chk for –ve error
mov indx_ce,#5h ;
ret
cen_vall: mov indx_ce,#1h ;
cemor_m: jb nce,cen_val2 ;more than medium error
mov indx_ce,#6h ;
ret
n_val2: mov indx_ce,#0h ;
ret
ceno_s: jnc cemor_s ;more than small ,chk
medium
sjmp cels_s ;less than small
ceno_m: jnc cemor_m
sjmp cels_m

……………………………………………………………………………………………
; This is an ISR routine for external event counter EX0,
………………………………………………………………………………………………

Ie0_isr:cpl zcd1_bit ;complement zcd


Setb pwm ;triac off
Mov t10,pwml ;load timer0
Mov tho,pwmh
Setb tr0 ;start timer0
Clr ie0
reti
………………………………………………………………………………………………
This is an ISR routin for external event counter EXI, 0.5 sec
………………………………………………………………………………………………

Ie1_isr:setb pwm
Cpl zcd2_bit
Mov t10,pwml ;load timer0
Mov t10,pwmh
Setb tr0 ;start timer0
Clr Ie 1
Reti

……………………………………………………………………………………………
This is an ISR routin for timer0
……………………………………………………………………………………………..
Tim0_isr: clr pwm ;triac on
Clr tr0 ;stop timer
Reti
………………………………………………………………………………………………
initialize variables
………………………………………………………………………………………………
ini_var:mov p3,#0ffh
Clr nebit ;clear bit
Clr nce ;
Clr zcd1_bit
Clr zcd2_bit
Setb pwm ;off triac
Reti
…………………………………………………………………………………………
Init timer 1
…………………………………………………………………………………………

Ini_tmr: mov tmod,#11h ;set timer 1 in timer mode


;mode=1,16 bit
Mov t10,#0feh
Mov tho,#0ffh ;load timer count
Mov t11,#0feh
Mov th1,#0ffh ;load timer count
Mov tcon,#05h ;ie0/ 1 falling edge
Mov iec,#87h ;int0/int1/timer0
Ret
…………………………………………………………………………………………….
This routine will read and display temperature of 1st sample.
Calculate E and CE
Destroy=ACC,DPTR,r3,r4
……………………………………………………………………………………….
Fst_read: icall temp_dekh ;read temperature
Lcall cal_error
Mov pe,error
Ret

………………………………………………………………………………………………
This routin will show display temperature
Destroy=ACC,DPTR,r3,r4
………………………………………………………………………………………………

Tmp_dekh: mov cur_pos,#0c7h;


Mov chnl,#0h;
Lcall adatard;
Rr a
Anl a,#07fh
Clr c
Subb a,#3 ;calibrate it
Lcall dat_disp ;display
Mov r2,#01h
T2: lcall delay
Djnz r2,t2
Ret

……………………………………………………………………………………………
; Keyboard routine
………………………………………………………………………………………………
This routine will chk for k/b hit. it scan all lines.
; px7 px6 px5 px4 px3 px2 px1 px0
; [output] [input]
; if no key pressed clear carry else set carry.
; Input: Nothing
;output :carry flag :0-no key
1-key available in accumulator
;destroy ; acc,B
………………………………………………………………………………………………

Ky_chk: mov r3, #08h ; counter


Mov a,#0eeh ;no previous. key pressed
Al: orl a,#0fh ;lower nibble as input
Mov kb_port,a ;o/p on keyboard port
Lcall dely_10 ; delay
Lcall dely_10 ;
Nop
Nop
Nop
Mov a,kb_port ;read keyboard port
Anl a,#0fh
Cjne a,#0fh,Ky_Avl ;if yes jump
Rr a ; route right
Djnz r3,al ;counter=counter
Clr c ; clear carry
Ret

Ky_avl: lcall delay_10 ; call delay 10ms


lcall delay_10
lcall delay_10
orl a,#0fh ;lower nibble as input
mov kb_port,a ;o/p on k/b port
nop
nop
nop
nop
nop
nop
mov a,kb_port ; read port 1
anl a,#0fh ;any key pressed?
Cjne a, #0fh, aa2
Jz ky_chk ;if no jump back
Aa2 mov a,kb_port ;if yes read key
Mov r0,#0 ;lookup table search
Mov r3,#10h ;
Mov b,a ;
Mov dptr,#ky_tbl ;
Lpc: mov a,#0 ;
Mov c a,@a+dptr ;
Inc dptr ;
Inc r0 ;
Cjne a,b,lo_c ;
Mov a,r0 ;
Clr c ;
Subb a,#01h ;
Setb c ; set carry
Ret ;

Lop_c djnz r3,lpc ;


Sjmp ky_chk ;

Ky_tbl: dfb 07eh ;0


Dfb 0beh ;1
Dfb 0deh ;2
Dfb 0eeh ;3
Dfb 07dh ;4
Dfb 0bdh ;5
Dfb 0ddh ;6
Dfb oedh ;7
Dfb 07bh ;8
Dfb 0bbh ;9
Dfb 0dbh ;a
dfb 0ebh ;b
dfb 077h ;c
dfb 0b7h ;d
dfb 0d7h ;e
dfb 0e7h ;f

;--------------------------------------------------------------------------------------------
;wait till kb not hit
;--------------------------------------------------------------------------------------------

Rdkbd: lcall ky_chk


Jnc rdkbd
Ret

;-------------------------------------------------------------------------------------------
;chk for key released
;-------------------------------------------------------------------------------------------

Ky_rls: mov a,#0fh ;port1 = o/p


Mov kb_port,a ;output on port 1
Lcall dly_10 ;settling time
Nop ;
Nop ;
Nop ;
Nop ;
Nop ;
Nop ;
Mov a,kb_port ;read port 1
Anl a,#0fh ;and lower nibble
Cjne a,#0fh,ky_rls ;chk for any key pressed
previously
Ret
………………………………………………………………………………………………
This routine will check for kb hit, set temperature
………………………………………………………………………………………………

Kyrout icall ky_chk


Jnc ky_0
Cjne a,#set_ky,ky_o ; no set key
Lcall set_temp ; set temperature
Mov dptr,#sgn_on ;display sgn_msg
Icall disp_16
Ky_0 ret
………………………………………………………………………………………………
this prog is to set time
………………………………………………………………………………………………

Set_temp: mov dptr,#st_msg ;display message


Lcall disp_16 ;
Mov r3, #99h ;
Mov a,set_t ;load hr on
Lcall routin 1
Mov set_t,a
Ret

St_msg: dfb ‘set temperature’


Dfb ‘set temperature’
Routin1: mov a,#0c7h
lcall lcd_wr
Lcall ot_d
Wa_it1 lcall rkkbd ; read key
Jnc wa_it1 ; wait till key pressed
Cjne a,#up,no_up ;dn ky?centre wala key
Add a,#01h ;data =data+1
Da a ;BCD data
Cjne a,#99h,routin1 ;chk for 24 hrs?
Movg a,#0h ;restart from 0
Sjmp routin1
No_up: cjne a,#slct,wa_it 1 ;chk for select key
Ret

************************************************************************
KB routines ends
Input: hex_1:hex_2(HEX data)
Output: convert input data to BCD
Display it on data field
………………………………………………………………………………………………
Dat_disp: mov hex_1,#0 ;take hex data
Mov hex_2,a
Push acc
Lcall hex_bcd :hex to BCD
Mov ct,hex_2 :store current temp in BCD
Mov r4,hex_1 :parameter passing to display
Mov r3,hex_2
Mov a,cur_pos ;load cursor position
Lcall disp ;display data
Mov a,indx_e
Lcall ot_d
Mov a,indx_ce
Lcall ot_d
Pop acc
Quito: ret

………………………………………………………………………………………………
message
------------------------------------------------------------------------------------------------------------
Sgn_on:dfb ‘fuzzy Controller’
Dfb temp=
Bl_nk: dfb ‘ ‘
Dfb , ‘

LCD module routines


initialize LCD module
………………………………………………………………………………………………
Ini_lcd move A,#30h ;reset command
lcall command

lcall dely_I0

mov a,#30h ;reset command

lcall command

lcall dely_l0

mov a,#30h ;reset command

lcall command
lcall dely_l0

mov a,#38h
leall command
lcall dely_10
mov a,#10h

lcall command

leall dely_l0

mov a,#0eh

lcall command
lcall dely_I0

mov a,#06h

lcall command

lcall dely_l0

mov a,#0lh

lcall command

lcall dely_l0

ret

;-----------------------------------------------------------------------------------------------------------
; This routin will provide command to LCD module
; port2 D7 D6 D5 D4 D3 D2 Dl D0
; l l l l l l l l
; E R/W RS
;RS = 0 (command reg access)
;R/W = 0 (write operation)
;EN = ( enable make 0/1/0)
;-----------------------------------------------------------------------------------------------------------
command: mov lcd _port,a
clr RS ;clr RS

clr RW ;write

nop
nop
nop
nop

nop

setb E ;EN= 1

nop

nop

nop

nop

nop

clr E ;EN= 0

ret

;-----------------------------------------------------------------------------------------------------------
; This routin will provide display data to LCD module
; RS = 1 ( data reg access)

; R/W = 0 ( write operation)

; EN = 1 (Enable make 0/1/0 )

;-----------------------------------------------------------------------------------------------------------
display: mov Lcd_port,a
setb RS ;set RS
;write
clr RW

nop
nop

nop

nop

setb E ;EN = 1

nop
nop
nop

nop

clr E ;EN = 0

ret

;-----------------------------------------------------------------------------------------------------------
; This routin will provide command to LCD module
;--------------------------------------------------------------------------------------------------------------------
-

You might also like