??? 07/29/06 03:51 Read: times |
#121298 - code optimisation |
This code is supposed to recieve a charecter from serial port, compare it with a set of hardcoded charecters, pull corresponding pins of port1 high or low depeding on the match and also send a feedback via serial port as to which pin of p1 has be altered. The poblem is, it sends the multiple feedbacks even if a single key is pressed at once(this is happening only for '!' and '#';DEVICE.1 and DEVICE.2 is being display more than once).
Also, i realise that this fits nowhere in a set of optimum codes since it takes up a lot of ROM space, anything I could do to optimise it? ;------------subroutine for sending string via serial port------ disp_message: push acc disp_message_loop1: mov a,#00h ; reset accumulator movc a,@a+dptr cjne a,#00h,disp_message_loop2 pop acc ret disp_message_loop2: mov sbuf,a acall tx_main ;sends a charecter via serial port inc dptr sjmp disp_message_loop1 disp_device_info:DB 0ch,0ah,0dh,"Device",09h,"Control",0ah,0dh,'1',09,'!',0ah,0dh,'2',09,'@',0ah,0dh,'3',09,'#',0ah,0dh,'4',09,'$',0ah,0dh,'5',09,'%',0ah,0dh,'6',09,'^',0ah,0dh,'7',09,'&',0ah,0dh,'8',09,'*',0ah,0dh,00h disp_device1_on: DB 0ah,0ah,0dh,"Device.1 ON",00h disp_device2_on: DB 0ah,0dh,"Device.2 ON",00h disp_device3_on: DB 0ah,0dh,"Device.3 ON",00h disp_device4_on: DB 0ah,0dh,"Device.4 ON",00h disp_device5_on: DB 0ah,0dh,"Device.5 ON",00h disp_device6_on: DB 0ah,0dh,"Device.6 ON",00h disp_device7_on: DB 0ah,0dh,"Device.7 ON",00h disp_device8_on: DB 0ah,0dh,"Device.8 ON",00h disp_device1_off: DB 0ah,0ah,0dh,"Device.1 OFF",00h disp_device2_off: DB 0ah,0dh,"Device.2 OFF",00h disp_device3_off: DB 0ah,0dh,"Device.3 OFF",00h disp_device4_off: DB 0ah,0dh,"Device.4 OFF",00h disp_device5_off: DB 0ah,0dh,"Device.5 OFF",00h disp_device6_off: DB 0ah,0dh,"Device.6 OFF",00h disp_device7_off: DB 0ah,0dh,"Device.7 OFF",00h disp_device8_off: DB 0ah,0dh,"Device.8 OFF",00h ;________________________________________________________________________________ ;--------------------------------main code--------------------------------------- ;________________________________________________________________________________ kcd_main:mov p1,#00h ;make output port mov sp,#64h mov IE,#00h acall s9k_main mov dptr,#disp_device_info ;display device controls acall disp_message ;sends a string through serial port mov p1,#0ffh ;switch off all devices mov DEVICE,#0ffh ;reset device control buffer(initially switch off all devices) kcd_main1:acall rx_main ;accept a charecter from serial port;recieved charecter's stored in acc kcd_dev1:cjne a,#'!',kcd_dev2 ;compare recieved cha with '!', if equal change status of device 1 cpl DEVICE.0 ;if not equal, compare next kcd_dev2:cjne a,#'@',kcd_dev3 ;compare recieved cha with '@', if equal change status of device 2 cpl DEVICE.1 ;if not equal, compare next kcd_dev3:cjne a,#'#',kcd_dev4 ;compare recieved cha with '#', if equal change status of device 3 cpl DEVICE.2 kcd_dev4:cjne a,#'$',kcd_dev5 cpl DEVICE.3 kcd_dev5:cjne a,#'%',kcd_dev6 cpl DEVICE.4 kcd_dev6:cjne a,#'^',kcd_dev7 cpl DEVICE.5 kcd_dev7:cjne a,#'&',kcd_dev8 cpl DEVICE.6 kcd_dev8:cjne a,#'*',kcd_operate ; after comparing all, the status info stored in DEVICE(20h) is written into port1 cpl DEVICE.7 ;------------------------------------- kcd_operate:mov p1,DEVICE mov a,DEVICE ;copy device status into a for feedback(as to device is on or of)sent via serial port mov dptr,#disp_device_info ;display device controls acall disp_message ;------------------------------------- kcd_check1: rrc a ;LSB is pushed to carry flag for comparision jc device1_off ;'0'=>ON; '1'=>OFF mov dptr,#disp_device1_on ;if carry='0', send "DEVICE.1 ON" acall disp_message sjmp kcd_check2 ;check next device1_off:mov dptr,#disp_device1_off ;if carry='1', send "DEVICE.1 OFF" acall disp_message ;------------------------------------- kcd_check2: rrc a jc device2_off mov dptr,#disp_device2_on acall disp_message sjmp kcd_check3 device2_off:mov dptr,#disp_device2_off acall disp_message ;------------------------------------- kcd_check3: rrc a jc device1_off mov dptr,#disp_device3_on acall disp_message sjmp kcd_check4 device3_off:mov dptr,#disp_device3_off acall disp_message ;------------------------------------- kcd_check4: rrc a jc device4_off mov dptr,#disp_device4_on acall disp_message sjmp kcd_check5 device4_off:mov dptr,#disp_device4_off acall disp_message ;------------------------------------ kcd_check5: rrc a jc device5_off mov dptr,#disp_device5_on acall disp_message sjmp kcd_check6 device5_off:mov dptr,#disp_device5_off acall disp_message ;------------------------------------- kcd_check6: rrc a jc device6_off mov dptr,#disp_device6_on acall disp_message sjmp kcd_check7 device6_off:mov dptr,#disp_device6_off acall disp_message ;------------------------------------- kcd_check7: rrc a jc device7_off mov dptr,#disp_device7_on acall disp_message sjmp kcd_check8 device7_off:mov dptr,#disp_device7_off acall disp_message ;------------------------------------- kcd_check8: rrc a jc device8_off mov dptr,#disp_device8_on acall disp_message ljmp kcd_main1 device8_off:mov dptr,#disp_device8_off acall disp_message ;-------------------------------------- ljmp kcd_main1 ;jump back to recieving charecter via serial port end |