{"id":156,"date":"2026-01-14T07:29:47","date_gmt":"2026-01-13T23:29:47","guid":{"rendered":"https:\/\/gccircuit.com\/wordpress\/?p=156"},"modified":"2026-01-14T07:31:10","modified_gmt":"2026-01-13T23:31:10","slug":"156","status":"publish","type":"post","link":"https:\/\/gccircuit.com\/wordpress\/2026\/01\/14\/156\/","title":{"rendered":"AT89C2051\u9a45\u52d5\u6b65\u9032\u99ac\u9054\u7684\u96fb\u8def\u548c\u7a0b\u5f0f\u78bc"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>stepper.c\nstepper.hex\n\n\/*\n* STEPPER.C\n* sweeping stepper's rotor cw and cww 400 steps\n* Copyright (c) 1999 by W.Sirichote\n*\/\n\n#include c:\\mc51\\8051io.h \/* include i\/o header file *\/\n#include c:\\mc51\\8051reg.h\n\nregister unsigned char j,flag1,temp;\nregister unsigned int cw_n,ccw_n;\n\nunsigned char step&#91;8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90}\n#define n 400\n\n\/* flag1 mask byte\n0x01 run cw()\n0x02 run ccw()\n*\/\n\nmain()\n\n{\nflag1=0;\nserinit(9600);\ndisable(); \/* no need timer interrupt *\/\ncw_n = n; \/* initial step number for cw *\/\nflag1 |=0x01; \/* initial enable cw() *\/\n\nwhile(1){\n{\ntick_wait(); \/* wait for 10ms elapsed *\/\n\nenergize(); \/* round-robin execution the following tasks every 10ms *\/\ncw();\nccw();\n}\n}\n\n}\n\ncw(){\nif((flag1&amp;0x01)!=0)\n{\ncw_n--; \/* decrement cw step number *\/\nif (cw_n !=0)\nj++; \/* if not zero increment index j *\/\nelse\n{flag1&amp;=~0x01; \/* disable cw() execution *\/\nccw_n = n; \/* reload step number to ccw counter *\/\nflag1 |=0x02; \/* enable cww() execution *\/\n}\n}\n\n}\n\nccw(){\nif((flag1&amp;0x02)!=0)\n{\nccw_n--; \/* decremnent ccw step number *\/\nif (ccw_n !=0)\nj--; \/* if not zero decrement index j *\/\nelse\n{flag1&amp;=~0x02; \/* disable ccw() execution *\/\ncw_n = n; \/* reload step number to cw counter *\/\nflag1 |=0x01; \/* enable cw() execution *\/\n}\n}\n\n}\n\ntick_wait(){ \/* cputick was replaced by simpler ASM code 10ms wait *\/\n\nasm' JNB TCON.5,*'; \/* wait for TF0 set *\/\nasm' CLR TCON.5'; \/* clear TF0 for further set *\/\nasm' ORL TH0,#$DC'; \/* reload TH0 with $DC, TL0 = 0 *\/\n}\n\nenergize(){\n\nP1 = step&#91;(j&amp;0x07)]; \/* only step 0-7 needed *\/\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":157,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-156","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-6"],"_links":{"self":[{"href":"https:\/\/gccircuit.com\/wordpress\/wp-json\/wp\/v2\/posts\/156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gccircuit.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gccircuit.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gccircuit.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gccircuit.com\/wordpress\/wp-json\/wp\/v2\/comments?post=156"}],"version-history":[{"count":2,"href":"https:\/\/gccircuit.com\/wordpress\/wp-json\/wp\/v2\/posts\/156\/revisions"}],"predecessor-version":[{"id":159,"href":"https:\/\/gccircuit.com\/wordpress\/wp-json\/wp\/v2\/posts\/156\/revisions\/159"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gccircuit.com\/wordpress\/wp-json\/wp\/v2\/media\/157"}],"wp:attachment":[{"href":"https:\/\/gccircuit.com\/wordpress\/wp-json\/wp\/v2\/media?parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gccircuit.com\/wordpress\/wp-json\/wp\/v2\/categories?post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gccircuit.com\/wordpress\/wp-json\/wp\/v2\/tags?post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}