answersLogoWhite

0


Want this question answered?

Be notified when an answer is posted

Add your answer:

Earn +20 pts
Q: What is the procedure to reset tmod register in 8051?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write delay routine for 1 millisecond using timer 0 of 8051 for 12MHZ crystal frequency?

DELAY: MOV TMOD,#00000001B // Sets Timer 0 to MODE1 (16 bit timer). Timer 1 is not used MOV TH0,#0FCH // Loads TH0 register with FCH MOV TL0,#018H // LOads TL0 register with 18H SETB TR0 // Starts the Timer 0 HERE: JNB TF0,HERE // Loops here until TF0 is set (ie;until roll over) CLR TR0 // Stops Timer 0 CLR TF0 // Clears TF0 flag RET


Delay program of 1 sec for microcontroller 89C51?

Mov tmod, #01h mov r0, #20 back:mov tl0,96 mov th0,60 setb tr0 again:jnb tf0, again clr tr0 clr tf0 djnz r0, back


Can you play Terraria online without downloading it?

It depends on the website you download it from, some might be unsafe that give you viruses or even possibly scamming you but some are safe but i recommend you buying it on Steam for legal and safe reasons


Ps2 interfacing keyboard by micro controller with assembly language solutions?

$mod52 ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; PORT DECLERATION ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% KEYB_CLOCK EQU P2.7 KEYB_DATA EQU P2.6 KB_LSHIFT EQU 12H KB_RSHIFT EQU 59H KB_CTRL EQU 14H KB_ALT EQU 11H KB_CAPS EQU 58H KB_SCROLL EQU 7EH KB_NUML EQU 77H KB_TAB EQU 0DH KB_REL EQU 0F0H KB_EXT EQU 0E0H KB_PAUSE EQU 0E1H CAPS EQU 01H NUML EQU 02H SCROLL EQU 04H SHIFT EQU 08H ACK EQU 10H CTRL EQU 20H ALT EQU 40H RELEASE EQU 80H PAUSED EQU 40H EXTENDED EQU 80H DSEG ; This is internal data memory ORG 20H ; Bit adressable memory FLAGS1: DS 1 RECEIVED BIT FLAGS1.0 AM BIT FLAGS1.1 MAS BIT FLAGS1.2 KEYBRD BIT FLAGS1.3 AMS BIT FLAGS1.4 CAPPS_ON: DS 1 CAAPS BIT CAPPS_ON KB_OK: DS 1 KB_DATA: DS 1 KB_STATS: DS 1 KB_SCAN: DS 1 KB_TEMP: DS 1 ; For the da*n pause key KB_COUNT: DS 1 NAMES: DS 16 COUNTT: DS 1 STACK: DS 1 CSEG ; Code begins here ; ---------==========----------==========---------=========--------- ; Main routine. Program execution starts here. ; ---------==========----------==========---------=========--------- ORG 00H ; Reset AJMP MAIN ORG 23H JMP SERIAL ; ---------==========----------==========---------=========--------- MAIN: MOV SP,#STACK MOV TMOD,#20H ;Enable Timer 1 from Baud rate Generation MOV TH1,#0FDH MOV SCON,#50H ;Enable serial port for 9600Baud rate SETB ES SETB EA ;Enable serial port interrupt SETB TR1 CALL InitKeyb ;Inizialize Keyboard MOV a, KB_OK JZ KBNotOK LOOPS: CALL Check_Keyb ;Check for any keypress JNC LOOPS MOV A,KB_DATA ;get data MOV SBUF,A AJMP LOOPS ;---------==========----------==========---------=========--------- ; SERIAL INTERRUPT ROUTINE ;---------==========----------==========---------=========--------- SERIAL: JB TI,TRANS CLR RI RETI TRANS: CLR TI RETI ;********************************************************** KBNotOK: AJMP $ ;Keyboard Error ;--------------------- ; Keyboard Routines: ;--------------------- ;************************************* ; WaitKB: Wait for keypress ;************************************* WaitKB: call Check_Keyb jnc WaitKB ret ;************************************* ; InitKeyb: c=1 if ACK OK ;************************************* CheckACK: mov a, KB_STATS mov c, acc.4 clr acc.4 mov KB_STATS, a ret ;************************************* ; InitKeyb: ;************************************* InitKeyb: mov KB_TEMP, #0 mov KB_OK, #0 mov r1, #0FFH call Write_Keyb call Check_Keyb call CheckACK jnc InitKeyb mov r1, #0F4H ; Enable call Write_Keyb call Check_Keyb call CheckACK jnc KeybErr mov r1, #0F3H ; Set Typematic call Write_Keyb call Check_Keyb call CheckACK jnc KeybErr mov r1, #00H ; Typematic = 250 ms / 30 cps call Write_Keyb call Check_Keyb call CheckACK jnc KeybErr mov KB_OK, #1 mov KB_STATS, #2 ; Num Lock ON ;************************************* ; Keyb_Leds: Set KB_STATS as leds ;************************************* Keyb_Leds: mov r1, #0EDH ; Set Leds call Write_Keyb call Check_Keyb call CheckACK jnc KeybErr mov r1, KB_STATS call Write_Keyb call Check_Keyb call CheckACK KeybErr: ret ;************************************* ; Zero2One: Wait for 0 to 1 on kb ; clock line, read the kb data line ; and shift right the bit to acc.7 ;************************************* Zero2One: jnb KEYB_CLOCK, $ jb KEYB_CLOCK, $ mov c, KEYB_DATA rrc a ret ;************************************* ; Check_Keyb: Check to see if any key ; are pressed or release, returns ; ASCII codes on KB_DATA, or 1 for ; special keys, 2 for same special ; with shift. Return also the scan ; code on KB_SCAN. ; Special Keys are basicaly all non ; printable keys. See the table below ; all 1 and 2 returned are special keys ;************************************* Check_Keyb: setb KEYB_DATA setb KEYB_CLOCK ; CLOCK & DATA high = Idle Pos mov r0, #50 CheckAgain: jnb KEYB_CLOCK, KeyHit djnz r0, CheckAgain ; check r0 times sjmp KeyEnd KeyHit: jnb KEYB_DATA, KeyHit2 ; Start bit must be 0 KeyEnd: clr KEYB_CLOCK ; disable keyb clr c ; c=0 = no keypress ret KeyHit2: mov r0, #8 ; 8 bits clr a KeyHit3: call Zero2One djnz r0, KeyHit3 mov r1, a clr a call Zero2One ; Parity bit call Zero2One ; Stop bit ; acc.7 = stop, acc.6 = parity clr KEYB_CLOCK mov a, KB_TEMP jz NoIgnore dec KB_TEMP ; Igonre pause scans sjmp ChkKbEndNC NoIgnore: mov KB_SCAN, r1 cjne r1, #0FAH, NoKbACK orl KB_STATS, #ACK sjmp ChkKbEndNC NoKbACK: cjne r1, #KB_PAUSE, NoKbPause mov KB_TEMP, #7 ; Ignore next 7 scans mov a, KB_OK cpl acc.6 mov KB_OK, a sjmp ChkKbEndNC NoKbPause: cjne r1, #KB_EXT, NoKbExt orl KB_OK, #EXTENDED sjmp ChkKbEndNC NoKbExt: cjne r1, #KB_REL, NoRelease orl KB_STATS, #RELEASE sjmp ChkKbEndNC NoRelease: ; Test Num lock, if pressed toggle led cjne r1, #KB_NUML, NoNumLock mov a, KB_STATS jnb acc.7, ChkKbEndNC cpl acc.1 clr acc.7 mov KB_STATS, a call Keyb_Leds sjmp ChkKbEndNC NoNumLock: ; Test Caps lock, if pressed toggle led cjne r1, #KB_CAPS, NoCapsLock mov a, KB_STATS jnb acc.7, ChkKbEndNC cpl acc.2 clr acc.7 mov KB_STATS, a call Keyb_Leds sjmp ChkKbEndNC NoCapsLock: ; Test Scroll lock, if pressed toggle led cjne r1, #KB_SCROLL, NoScrollLock mov a, KB_STATS jnb acc.7, ChkKbEndNC cpl acc.0 clr acc.7 mov KB_STATS, a call Keyb_Leds ChkKbEndNC: clr c ret NoScrollLock: ; Test L & R shifts, set bit if pressed, clear on release cjne r1, #KB_LSHIFT, NoShift1 ShiftOK: mov a, KB_STATS jbc acc.7, ShiftRel setb acc.3 ; not releasing, so Set SHIFT bit sjmp ShiftEnd ShiftRel: clr acc.3 ; releasing, so Clear SHIFT bit ShiftEnd: mov KB_STATS, a sjmp ChkKbEndNC NoShift1: cjne r1, #KB_RSHIFT, NoShift sjmp ShiftOK NoShift: cjne r1, #KB_CTRL, NoCtrl mov a, KB_STATS jbc acc.7, CtrlRel setb acc.5 ; not releasing, so Set CTRL bit sjmp CtrlEnd CtrlRel: clr acc.5 ; releasing, so Clear SHIFT bit CtrlEnd: mov KB_STATS, a sjmp ChkKbEndNC NoCtrl: cjne r1, #KB_ALT, NoAlt mov a, KB_STATS jbc acc.7, AltRel setb acc.6 ; not releasing, so Set ALT bit sjmp AltEnd AltRel: clr acc.6 ; releasing, so Clear ALT bit AltEnd: mov KB_STATS, a sjmp ChkKbEndNC NoAlt: mov a, KB_STATS ; Releasing key test jnb acc.7, NoRel2 clr acc.7 ; if releasing > clear mov KB_STATS, a ; rel bit on KB_STATS clr c ; and do nothing ret NoRel2: mov a, KB_OK ; Extended key test jnb acc.7, KbChars clr acc.7 ; if Extended > clear mov KB_OK, a ; EXT bit on KB_OK clr c ; and do nothing ret KbChars:mov dptr, #KbScanCodes mov a, KB_STATS jnb acc.2, TestShift jb acc.3, KbChkOK mov a, r1 movc a, @a+dptr mov r0, a subb a, #97 jc KbChkOK mov a, r0 subb a, #123 jnc KbChkOK mov dptr, #KbScanCodes2 ; if (a to z) & Caps > table 2 sjmp KbChkOK TestShift: jnb acc.3, KbChkOK mov dptr, #KbScanCodes2 ; with shift table 2 KbChkOK: mov a, r1 movc a, @a+dptr mov KB_DATA, a setb c ret ;************************************* ; Zero2One2: Wait for high to low in ; kb clock line ;************************************* Zero2One2: jnb KEYB_CLOCK, $ jb KEYB_CLOCK, $ ret ;************************************* ; Write_Keyb: Send r1 to the kb ;************************************* Write_Keyb: mov r0, #8 ; 8 bits to receive clr KEYB_CLOCK ; break the Keyboard mov r7, #00H ; some delay (safety reasons) _WKwait:djnz r7, _WKwait clr KEYB_DATA ; request to send setb KEYB_CLOCK ; enable the Keyboard acall Zero2One2 ; Start Bit mov a, r1 ; Data Bits TxData: rrc a mov KEYB_DATA, c call Zero2One2 djnz r0, TxData mov a, r1 ; calculate parity bit mov c, psw.0 ; this is Even parity cpl c ; and Keyboard needs Odd parity mov KEYB_DATA, c ; send parity bit call Zero2One2 setb KEYB_DATA ; send stop bit call Zero2One2 call Zero2One2 mov c, KEYB_DATA ; get ACK bit clr KEYB_CLOCK ; stop the keyboard ret ;************************************* ; last 262 addr of code mem with scan codes tables ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ; last 262 addr of code mem with scan codes tables KbScanCodes: ; Keyboard Scancodes ; ?, F9, ?, F5, F4, F1, F2, F12, ?, F10, F8, F6, F4, TAB, ~ db 0, 1 , 0, 1 , 1 , 1 , 1 , 1 , 0, 1 , 1 , 1 , 1 , 1 , '~' ; ?, ?,Lalt,Lshf, ?,Lctr, Q , ! , ?, ?, ?, Z , S , A , W , @ db 0, 0, 0 , 0 , 0, 0 , 'q', '1', 0, 0, 0, 'z', 's', 'a', 'w', '2' ; ?, ?, C , X , D , E , $ , # , ?, ?, " ", V , F , T , R db 0, 0, 'c', 'x', 'd', 'e', '4', '3', 0, 0, ' ', 'v', 'f', 't', 'r' ; % , ?, ?, N , B , H , G , Y , ^ , ?, ?, ?, M , J , U , & db '5', 0, 0, 'n', 'b', 'h', 'g', 'y', '6', 0, 0, 0, 'm', 'j', 'u', '7' ; * , ?, ?, < , K , I , O , ) , ( , ?, ?, > , ? , L , : , P db '8', 0, 0, ',', 'k', 'i', 'o', '0', '9', 0, 0, '.', '/', 'l', ';', 'p' ; _ , ?, ?, ?, " , ?, { , + , ?, ?,Caps,Rshf,Entr, } , ?, | db '-', 0, 0, 0, 39 , 0, '[', '=', 0, 0, 0 , 0 , 1 , ']', 0, 92 ; ?, ?, ?, ?, ?, ?, ?, ?,BkSp, ?, ?, 1 , ?, 4 , 7 , ?, ?, ?, 0 db 0, 0, 0, 0, 0, 0, 0, 0, 1 , 0, 0, '1', 0, '4', '7', 0, 0, 0, '0' ; . , 2 , 5 , 6 , 8 , ESC,Numl, F11, + , 3 , - , * , 9 ,Scrl db '.', '2', '5', '6', '8', 1 , 0 , 1 , '+', '3', '-', '*', '9', 0 ; ?, ?, ?, ?, F7 db 0, 0, 0, 0, 1 KbScanCodes2: ; Keyboard Scancodes with shift ; ?, F9, ?, F5, F4, F1, F2, F12, ?, F10, F8, F6, F4, TAB, ~ db 0, 2 , 0, 2 , 2 , 2 , 2 , 2 , 0, 2 , 2 , 2 , 2 , 2 , '`' ; ?, ?,Lalt,Lshf, ?,Lctr, Q , ! , ?, ?, ?, Z , S , A , W , @ db 0, 0, 0 , 0 , 0, 0 , 'Q', '!', 0, 0, 0, 'Z', 'S', 'A', 'W', '@' ; ?, ?, C , X , D , E , $ , # , ?, ?, " ", V , F , T , R db 0, 0, 'C', 'X', 'D', 'E', '$', '#', 0, 0, ' ', 'V', 'F', 'T', 'R' ; % , ?, ?, N , B , H , G , Y , ^ , ?, ?, ?, M , J , U , & db '%', 0, 0, 'N', 'B', 'H', 'G', 'Y', '^', 0, 0, 0, 'M', 'J', 'U', '&' ; * , ?, ?, < , K , I , O , ) , ( , ?, ?, > , ? , L , : , P db '*', 0, 0, '<', 'K', 'I', 'O', ')', '(', 0, 0, '>', '?', 'L', ':', 'P' ; _ , ?, ?, ?, " , ?, { , + , ?, ?,Caps,Rshf,Entr, } , ?, | db '_', 0, 0, 0, '"', 0, '{', '+', 0, 0, 0 , 0 , 2 , '}', 0, '|' ; ?, ?, ?, ?, ?, ?, ?, ?,BkSp, ?, ?, 1 , ?, 4 , 7 , ?, ?, ?, 0 db 0, 0, 0, 0, 0, 0, 0, 0, 2 , 0, 0, '1', 0, '4', '7', 0, 0, 0, '0' ; . , 2 , 5 , 6 , 8 , ESC,Numl, F11, + , 3 , - , * , 9 ,Scrl db '.', '2', '5', '6', '8', 2 , 0 , 2 , '+', '3', '-', '*', '9', 0 ; ?, ?, ?, ?, F7 db 0, 0, 0, 0, 2 END