??? 04/25/04 21:53 Read: times |
#69173 - PWM codes.......AT89C52 Responding to: ???'s previous message |
Hello Ijaz this is the codes.
$NOMOD51 #include <reg52.inc> ;***************************************************** ;program to generate PWM using AT89C52 * ;***************************************************** RAM EQU 0F000H ;External DATA (RAM) Starts here RAMEND EQU 0FFFFH ;External DATA (RAM) Ends here ;*************************************************** ; SETUP THE NAMES OF THE SEFGMENTS ;*************************************************** BUFF_SEG SEGMENT IDATA DATA_SEG SEGMENT DATA CODE_SEG SEGMENT CODE ;**************************** ; byte/word variables ; ;**************************** RSEG DATA_SEG org 0008h cputick: DS 1 PWM1: DS 2 PWM2: DS 2 time: DS 2 ;**************************************************** ; stack support ; ;**************************************************** RSEG BUFF_SEG STACK: DS 10 ;*************************************************** ; MAIN PROGRAM INITIALIZATION ; ;*************************************************** RSEG CODE_SEG USING 0 ; use register block 0 ORG 8000h ;CODE Starts here (normally in ROM) LJMP start ORG 800BH ORL TH0,#0DCh ;reload timer 0 for 10 ms INC cputick RETI ;********************************************************************************** ;service timer2 auto reload shift 16-bit PWM pattern to P1.7 and P1.6 every 1/1000 s ;********************************************************************************** org 802bh PUSH PSW PUSH ACC ;******************************************** ;PWM1 is for motor 1 shifted through P1.7 ;********************************************** clr C MOV A,PWM1 RLC A MOV PWM1,A MOV A,PWM1+1 RLC A MOV PWM1+1,A MOV P1.7,C ;P1.7 for motor 1 MOV A,PWM1 MOV ACC.0,C MOV PWM1,A ;********************************************** ;PWM2 is for motor 2 shifted through P1.6 ;********************************************** clr C MOV A,PWM2 RLC A MOV PWM2,A MOV A,PWM2+1 RLC A MOV PWM2+1,A MOV P1.6,C ;P1.6 for motor 2 MOV A,PWM2 MOV ACC.0,C MOV PWM2,A POP ACC POP PSW reti ;************************************************************************ ;Fixed memory locations for alternate access to the R0-R7 register bank.; ;************************************************************************ ?R0 EQU 0 ;Used for "POP" from stack ?R1 EQU ?R0+1 ;Used to load index indirectly ?R2 EQU ?R0+2 ;"" "" "" "" ?R3 EQU ?R0+3 ;Used by some runtime lib functions ?R4 EQU ?R0+4 ?R5 EQU ?R0+5 ?R6 EQU ?R0+6 ?R7 EQU ?R0+7 org 8100 DB 0A5H,0E5H,0E0H,0A5H ;signature bytes DB 253,255,0,0 ;id 253 = startup DB 0,0,0,0 ;prompt code vector DB 0,0,0,0 DB 0,0,0,0 DB 0,0,0,0 DB 0,0,0,0 DB 255,255,255,255 ;length and checksum (255=unused) DB 'Main Controller',0 ORG 8100+64 ;executable code begins here start: MOV SP,#stack-1 ;Set up initial stack CLR A ;Get end of list flag MOVX @DPTR,A ;Set heap ending address orl TMOD,#00000001b ;set timer 0 to be counter 16 bit SETB IE.7 ;set bit EA SETB IE.1 ;set bit ET0 Enable timer 0 interrupt SETB TCON.4 ;start timer 0 mov 0c9H,00H ;T2MOD address is $C9 MOV RCAP2H,#0FCh MOV RCAP2L,#65 mov T2CON,#00000001b ;start timer 2 producing 1kHz signal SETB IE.5 ;enable timer2 interrupt end |
Topic | Author | Date |
T2MOD......AT89C52 | 01/01/70 00:00 | |
RE: T2MOD......AT89C52 | 01/01/70 00:00 | |
RE: T2MOD......AT89C52 | 01/01/70 00:00 | |
RE: T2MOD......AT89C52 | 01/01/70 00:00 | |
RE: T2MOD......AT89C52 | 01/01/70 00:00 | |
RE: T2MOD......AT89C52 | 01/01/70 00:00 | |
RE: T2MOD......AT89C52 | 01/01/70 00:00 | |
RE: T2MOD......AT89C52 | 01/01/70 00:00 | |
identify the coils?? | 01/01/70 00:00 | |
identify the coils?? | 01/01/70 00:00 | |
RE: Stepper Motors![]() | 01/01/70 00:00 | |
PWM codes.......AT89C52 | 01/01/70 00:00 | |
RE: PWM codes.......AT89C52 | 01/01/70 00:00 | |
more explination plz | 01/01/70 00:00 | |
RE: more explination plz | 01/01/70 00:00 | |
RE: more explination plz | 01/01/70 00:00 | |
RE: more explination plz | 01/01/70 00:00 | |
concept | 01/01/70 00:00 | |
RE: concept | 01/01/70 00:00 |