temp = tolower(fifo_getch()); //get 1 character from buffer if (temp == 'a') PDOUT ^= 0x08; //toggle PD3 if (temp == 's') PDOUT ^= 0x10; //toggle PD4
#include <ez8.h>#include <sio.h>#define RELOAD_VALUE 18432 //PWM period (sec.) = (RELOAD x Prescaler)/system clock (Hz)#define PWM_VALUE1 9216 //7.5% duty cycle#define PWM_VALUE2 4608 //10% duty cycle#define PWM_VALUE3 13824 //5% duty cycle#define TMODE 0x03 //Timer mode is PWM mode#define PRESCALER 0x04 //prescaler = 4void init_PWM(void) //configure Timer 1{ DI (); T1CTL &= ~0x80; //Disable Timer 1 T1CTL |= (PRESCALER << 3) | TMODE; //Prescaler = 0, PWM mode T1CTL |= 0x40; //TPOL = 1. PC1/T1OUT output set to high //PWM output is initially high and //toggle to low when PWM_VALUE is reached T1H = 0x00; ` //initial value is 1 T1L = 0x01; T1PWMH = (PWM_VALUE1 >> 8); //PWM_VALUE loaded, set duty cycle T1PWML = (PWM_VALUE1 & ~0xFF00); T1RH = (RELOAD_VALUE >> 8); //RELOAD_VALUE loaded, set PWM period T1RL = (RELOAD_VALUE & ~0xFF00); IRQ0ENH &= ~0x40; //Timer 1 interrupt disabled IRQ0ENL &= ~0x40; PCDD |= 0x20; //PCI/T1OUT pin is output PCAF |= 0x20; //turn on alternate function of PC1, T1CTL |= 0x80; //Enable Timer 1 EI ();}void init_pushbuttons(void){ PDDD |= 0x04; //PD2 is input PDAF &= ~0x04; PDDD |= 0x08; //PC3 is input PDAF &= !0x08;}void main (){unsigned char val = 0x00init_pushbuttons(); //intialize PC2 and PD1 as input pinsinit_PWM(); //initialize timer1, PWM modewhile(1){if val = PDIN & 0x04; //if pushbutton1 is pressed { T1PWMH = (PWM_VALUE2 >> 8); //change to 10% duty cycle T1PWML = (PWM_VALUE2 & ~0xFF00); //servomotor turn counter //clock-wise (CCW) } if val = PDIN & 0x08; //if pushbutton2 is pressed { T1PWMH = (PWM_VALUE# >> 8); //change to 5% duty cycle T1PWML = (PWM_VALUE3 & ~0xFF00); //servomotor turn clock-wise (CW) } }}
#pragma interrupt
request naman po ng code ng pagamit ng internal ADC ng encore xp, kunyari babasahin ko yung 3 sensor ng mobot tnx
opo sir, yung black lines, gusto ko sana i diretso na sa ADC ng MCU yung pagsense, tsaka gusto ko po sana maglagay ng pang sense din ng ambient light for compensation kaya gusto ko sana sa ADC na i feed
helo poh maam and sir... same lng po ba and program sa lht ng z8 gamit and C ?.. like un 40 pins and sa Z8F0822 ?salamat po in advance-sHeinrich
Mga sir,Tanong ko lang po kung pwede ma-contol ng MCU ang speed ng isang DC motor gamit mga GPIO lang at walang TIMER?Kung pwede ito, through PWM din po ba?Pano po kaya code nito?Halimbawa po, initially umaandar na ung DC motor, then kapag may pinindot na push-button bibilis ang ikot nung motor. Kapag hinold down ung push-button, maabot nung motor ung max speed and constant na dun.And a different push-button para naman pabagalin ung ikot nung motor.Pwede po marequest ang code?Salamat po. Pasensya na po at beginner sa programming ng MCU.
mga boss...post naman kau code in C language ng pagcontrol ng 4 servo using pwm module ng uC. Nde ko kaz maintindihan ung nahanap ko na code eh, PIC and assembly kasi ung ginamit nya.......panu b kokontrolin ung apat, isa isa po ba na e aaces ung nga servo. -ganito po kasi ung naiisip ko -> access servo 1 then, send desired pulse width, after mgturn sa desired angle -> access servo 2 then, send desired pulse width, after mgturn sa desired angle -> access servo 3 then, send desired pulse width, after mgturn sa desired angle -> access servo 4 then, send desired pulse width