欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
不帶ADC的OTP單片機實現(xiàn)電位計控制PWM程序
[打印本頁]
作者:
amu_cpln
時間:
2021-12-9 01:20
標(biāo)題:
不帶ADC的OTP單片機實現(xiàn)電位計控制PWM程序
這方案比 555 的便宜, 不用外接他和電阻電容
用兩個普通IO口實現(xiàn)讀電位器, 調(diào)試輸出波形
可以達到任何頻率
附件的程序用了12F509 做的, 可以直接用在 0.3元的OTP單片機上
單片機源程序如下:
#include <12F509.h>
#fuses INTRC,NOWDT,NOPROTECT, NOMCLR
#use delay(clock=4000000)
#define GP0 PIN_B0
#define GP1 PIN_B1
#define GP2 PIN_B2
#define GP3 PIN_B3
#define GP4 PIN_B4
#define GP5 PIN_B5
#define set_options(value) {#ASM \
MOVLW value \
OPTION \
#ENDASM}
#define UART_TX_HI() output_high(GP2)
#define UART_TX_LO() output_low(GP2)
#define BitTime 40
void GP5_In()
{
output_low (GP5);
set_tris_b(0xfa);
}
void GP5_Out()
{
set_tris_b(0xda);
output_high (GP5);
}
unsigned char duty;
unsigned char i;
void cycle_backward (void)
{
output_low (GP2);
delay_us (70);
output_high (GP2);
delay_us (70);
}
void Get_Pos()
{
set_tris_b(0xfa); //GP5 input
while(input(GP5) == 0)
{
duty++;
}
set_tris_b(0xda); //GP5 output
}
void GetAdc()
{
duty = 0;
output_high(GP4); //Activate Pullup
while(input(GP5) == 0)
{
duty++;
if(duty==255)
{
output_low(GP4);
return;
}
}
output_low(GP4); // No pullup
}
void UART_Transmit(unsigned char DataValue)
{
/* Basic Logic
TX pin is usually high. A high to low bit is the starting bit and
a low to high bit is the ending bit. No parity bit. No flow control.
BitCount is the number of bits to transmit. Data is transmitted LSB first.
*/
// Send Start Bit
UART_TX_LO();
delay_us(BitTime); //delay_us(33); //
for ( i = 0; i < 8; i++ )
{
// Set Data pin according to the DataValue
if( ((DataValue>>i)&0x1) == 0x1 ) // If Bit is high
{
UART_TX_HI();
}
else // If Bit is low
{
UART_TX_LO();
}
delay_us(BitTime); //delay_us(33); //
}
// Send Stop Bit
UART_TX_HI();
delay_us(BitTime); //delay_us(33); //
}
/*
REVERT THE HARDWARE TO USING 2 PINS FOR POTENTIOMETER MEASUREMENT
USE A CAPACITOR OF 22PF TO 100PF
USE A TIMER TO HAVE THE PULSE CONTROL
>SETUP TIMER0 SO THAT 256 COUNTS = PULSE PERIOD(1 MSEC)
RUN TIMER 0
WHILE LOOP
>GETADC
>IF DUTY MORE THAN MAX VALUE, ALWAYS ON
>ELSE IF DUTY = 0, ALWAYS OFF
>ELSE IF TIMER COUNT = DUTY, OUTPUT ON
IF TIMER COUNT = 255, OUTPUT OFF
*/
void main()
{
set_options(0x07);
set_tris_b(0xfa); //GP2 and GP0 are outputs
setup_counters (RTCC_INTERNAL,RTCC_DIV_2);
output_low(GP5); //no pullup for GP5
while (TRUE)
{
//UART_Transmit(0);
//GetAdc();
//Get_Pos();
//UART_Transmit(duty>>8);
set_tris_b(0xfa); //GP5 input
set_timer0(0);
while(input(GP5) == 0)
{
}
duty = get_timer0();
set_tris_b(0xda); //GP5 output
//UART_Transmit(0);
//UART_Transmit(duty);
//delay_us(BitTime);
if(duty<95)
{
if(duty < 4)
{
output_high(GP0);
delay_ms(1);
}
else
{
output_low(GP0);
for(i=0;i<duty;i++)
{
delay_us(50);
}
duty = 100 - duty;
output_high(GP0);
for(i=0;i<duty;i++)
{
delay_us(50);
}
}
}
else
{
output_low(GP0);
delay_ms(1);
}
}
}
復(fù)制代碼
作者:
hjx5548
時間:
2021-12-16 15:47
能不能提供一下原理圖
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1