Untitled
unknown
plain_text
9 months ago
5.5 kB
4
Indexable
; Define the special function register addresses with different names PORT0 EQU 80H ; Port 0 address PORT3 EQU 90H ; Port 3 address ; Define interrupt vectors ORG 0000H ; Origin, start of the code LJMP MAIN ; Jump to main program ORG 003H ; Interrupt vector address for external interrupt 0 LJMP BUTTON_ISR ; Jump to button ISR ; Start of the program MAIN: SETB PORT0.0 ; Ensure LED is off initially ; Configure serial communication MOV TMOD, #20H ; Timer 1 in mode 2 (8-bit auto-reload) MOV TH1, #0FDH ; Load TH1 to set baud rate (9600 for 11.0592 MHz crystal) MOV SCON, #50H ; Configure serial mode (8-bit UART) SETB TR1 ; Start Timer 1 ; Configure external interrupt 0 (P3.2) for falling edge trigger SETB P3.2 ; Set P3.2 as input (button connected here) SETB EX0 ; Enable external interrupt 0 SETB IT0 ; Set interrupt 0 for falling edge trigger ; Enable global interrupts SETB EA ; Main program loop MAIN_LOOP: SJMP MAIN_LOOP ; Infinite loop to wait for interrupts (or other main program logic) ; External interrupt 0 service routine BUTTON_ISR: ACALL BLINK_LED ; Call subroutine to blink LED ACALL SEND_SMS ; Call subroutine to send SMS RETI ; Return from interrupt ; Blink LED subroutine BLINK_LED: MOV R3, #20 ; Load R3 with blink count (adjust as needed) BLINK_LOOP: CLR PORT0.0 ; Set PORT0.0 to turn on the LED ACALL DELAY_ROUTINE ; Call delay subroutine (for on time) SETB PORT0.0 ; Clear PORT0.0 to turn off the LED ACALL DELAY_ROUTINE ; Call delay subroutine (for off time) DJNZ R3, BLINK_LOOP ; Decrement R3, repeat blink if not zero RET ; Return from subroutine ; Delay subroutine with reduced delay for faster blinking DELAY_ROUTINE: MOV R2, #150 ; Adjusted delay count for faster blinking DELAY_LOOP1: MOV R1, #150 ; Adjusted delay count for faster blinking DELAY_LOOP2: NOP ; No operation, 1 cycle NOP ; No operation, 1 cycle DJNZ R1, DELAY_LOOP2 ; Decrement R1, jump if not zero DJNZ R2, DELAY_LOOP1 ; Decrement R2, jump if not zero RET ; Return from subroutine ; Subroutine to send SMS SEND_SMS: MOV A, #"A" ; Send "AT" command ACALL SEND_CHAR MOV A, #"T" ACALL SEND_CHAR MOV A, #0DH ; Carriage return ACALL SEND_CHAR ACALL WAIT_FOR_OK ; Wait for "OK" response MOV A, #"A" ; Send "AT+CMGF=1" command ACALL SEND_CHAR MOV A, #"T" ACALL SEND_CHAR MOV A, #"+" ACALL SEND_CHAR MOV A, #"C" ACALL SEND_CHAR MOV A, #"M" ACALL SEND_CHAR MOV A, #"G" ACALL SEND_CHAR MOV A, #"F" ACALL SEND_CHAR MOV A, #"=" ACALL SEND_CHAR MOV A, #"1" ACALL SEND_CHAR MOV A, #0DH ; Carriage return ACALL SEND_CHAR ACALL WAIT_FOR_OK ; Wait for "OK" response MOV A, #"A" ; Send "AT+CMGS=\"+601158051910\"" command ACALL SEND_CHAR MOV A, #"T" ACALL SEND_CHAR MOV A, #"+" ACALL SEND_CHAR MOV A, #"C" ACALL SEND_CHAR MOV A, #"M" ACALL SEND_CHAR MOV A, #"G" ACALL SEND_CHAR MOV A, #"S" ACALL SEND_CHAR MOV A, #"=" ACALL SEND_CHAR MOV A, #"\" ACALL SEND_CHAR MOV A, #"+" ACALL SEND_CHAR MOV A, #"6" ACALL SEND_CHAR MOV A, #"0" ACALL SEND_CHAR MOV A, #"1" ACALL SEND_CHAR MOV A, #"1" ACALL SEND_CHAR MOV A, #"5" ACALL SEND_CHAR MOV A, #"8" ACALL SEND_CHAR MOV A, #"0" ACALL SEND_CHAR MOV A, #"5" ACALL SEND_CHAR MOV A, #"1" ACALL SEND_CHAR MOV A, #"9" ACALL SEND_CHAR MOV A, #"1" ACALL SEND_CHAR MOV A, #"0" ACALL SEND_CHAR MOV A, #"\" ACALL SEND_CHAR MOV A, #0DH ; Carriage return ACALL SEND_CHAR ACALL WAIT_FOR_PROMPT ; Wait for ">" prompt MOV A, #"H" ; Send "HELLO" message ACALL SEND_CHAR MOV A, #"E" ACALL SEND_CHAR MOV A, #"L" ACALL SEND_CHAR MOV A, #"L" ACALL SEND_CHAR MOV A, #"O" ACALL SEND_CHAR MOV A, #1AH ; Ctrl+Z to indicate end of message ACALL SEND_CHAR ACALL WAIT_FOR_OK ; Wait for "OK" response RET ; Subroutine to send a character over serial SEND_CHAR: CLR TI MOV SBUF, A WAIT: JNB TI, WAIT RET ; Wait for "OK" response WAIT_FOR_OK: MOV R7, #255 WAIT_OK_LOOP: JNB RI, WAIT_OK_LOOP ; Wait for serial interrupt (data received) MOV A, SBUF CLR RI CJNE A, #"O", WAIT_OK_LOOP ; Check for "O" JNB RI, WAIT_OK_LOOP MOV A, SBUF CLR RI CJNE A, #"K", WAIT_OK_LOOP ; Check for "K" RET ; Wait for ">" prompt WAIT_FOR_PROMPT: MOV R7, #255 WAIT_PROMPT_LOOP: JNB RI, WAIT_PROMPT_LOOP ; Wait for serial interrupt (data received) MOV A, SBUF CLR RI CJNE A, #">", WAIT_PROMPT_LOOP ; Check for ">" RET ; Delay subroutine for AT command processing DELAY1: MOV R2, #10 DELAY1_LOOP1: MOV R1, #255 DELAY1_LOOP2: DJNZ R1, DELAY1_LOOP2 DJNZ R2, DELAY1_LOOP1 RET END ; End of the program
Editor is loading...
Leave a Comment