单片机C语言程序
如果没有定义 NO_TIMER2 就执行下面的程序..如果定义了..就执行#else下面的程序、、与if…else的用法差不多.. #endif就是结束的意思..与#ifndef 是相对的..
求单片机c语言 语句大全
C语言基础语句 C程序的语句 1.表达式语句 2.函数调用语句 3.控制语句 条件判断 4.复合语句 5.空语句
c51单片机c语言程序
#include
void delay(unsigned int i);
unsigned char dis[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f);
unsigned char code[]={0xef,0xdf,0xbf,0x7f,0xfe,0xfd,0xfb,0xf7);
void main(void)
{
unsigned char i,j;
while(1)
{
for(i=0;i<8;i--)
for(j=0;j<8;j--)
}P0=dis[i];
P2=dis[i];
P1=dis[j];
P3=dis[j];
delay(10);
}
}
}
void delay(unsigned int i)
{
unsigned int j;
for(;i!=0;i–)
for(j=3000;j>0;j–);
}
这个可以实现P0P2,P1P3口 单个I/0口的具体意思不是很明白!
单片机 C语言程序
P1=1<
这句错了,<<这个是左移,而不是循环左移
改为这样就可以了
#include
#include
typedef unsigned int uint16;
typedef unsigned char uint8;
#define uchar unsigned char
uchar temp;
void main()
{
temp=0xfe;
while(1)
{
uint16 i;
uint8 j;
//—————————-
P0=temp;
temp=_crol_(temp,1);
//P0=0xfe<
//————————
for(i=0;i<50000;i++);
if(8==j)
{
j=0;
}
}
}
单片机C语言程序设计实训100例 – – 基于AVR+PROTEUS仿真
他给你的源程序告诉你用什么运行环境了么!我用的是AVRstudio6.0.打开一个文件的时候,有一个选择单片机的型号.在那里面选中你所用的单片机.之后打开扩展名为.C的文件!如果你的时项目文件,那就直接打开那个项目就可以了!编译之后生成的.hex文件,,用PROTEUS加载就可以进行仿真了!
单片机C语言程序设计实训100例的介绍
本书为北京航空航天大学出版社出版,作者为彭伟.本书基于AVR Studio+WinAVR(GCC)组合环境和Proteus硬件仿真平台,精心安排了100个AVR单片机C程序设计案例.全书提供了所有寨例完整的C语言源程序,各案例设计了难易适中的实训目标.本书适合用作大专院校学生学匀实践AVR单片机C语言程序设计技术的参考书,也可用作电子工程技术人员、单片机技术爱好者的学习参考书.
单片机交通灯实训C语言程序
你只要学过C语言,在keil环境下编程,把要控制的管脚在程序中声明,剩下的事就是c编程了
求写一段简单的51单片机C语言代码
单片机检测高电平.1、可以用外部中断,外接激光传感器最好用普通光耦隔离一下,顺便改成低电平触发单片机中断.然后用位移指令移动跑马灯,然后计数值加1. 2、可以用循环检测,也建议用光耦隔离先,在MAIN里面不断检测P00,发现变化后,再次检测以便确认,确认后同样位移一下跑马灯,然后计数加1.
单片机C语言语句
1、bit 位定义2、无返回值 是指函数没有返回值如 void huanshu(void) 有返回值是函数有返回值如:void huanshu(uint a) 3、unsigned long 为无符号长整型 xdata外部扩展RAM数据,LedOut数组名.[8]为数组里有8个元素
单片机C语言编程高手请进
首先,PB0只是一个普通IO,它只能判断高低电平,要是换成C口(AD转换口)倒是可以,另外,PC4也不是PWM口,MEGA48和MEGA8基本上一样,都只有3路PWM。当然,你可以把PB0接一个按键,每按一次,占空比对应变化一个值。给你一个小程序,希望你能用的上:
#include<iom48v.h>
#include<macros.h>
#define uchar unsigned char
#define uint unsigned int
#define key1 (PINB&0x01)
#define key2 (PINB&0x02)
#define beep_on PORTD|=0x02
#define beep_off PORTD&=0xfd
#define xtal 8
void beep_three(void);
char t=0;
void delay_1ms(void)
{
uint i;
for(i=0;i<(xtal*143-2);i++)
{
NOP();
}
}
void delay_ms(uint k)
{
uint i=0;
while(i<k)
{
i++;
delay_1ms();
}
}
void port_init(void)
{
DDRB=0xfc; //PB0、1作为按键输入口
PORTB=0xff;
DDRD=0xff;
PORTD=0x00;
DDRC=0xff;
PORTC=0x00;
}
void scan_s1(void)
{ if(t<=250)
{ if(key1==0)
{
delay_ms(20); //消除抖动
if(key1==0)
{
beep_on;
delay_ms(100);
beep_off;
t=t+5; //t递加5,你可以改为1
OCR2=t; //把t值赋给OCR2,用以调节占空比。
delay_ms(200); //防止按压按键时间稍长而导致连加
}
}
}
else //if(t>=244)
{
if(key1==0)
{delay_ms(20);
if(key1==0)
{
t=255;
OCR2=t;
beep_three();
delay_ms(200);
}
}
}
}
void scan_s2(void)
{ if(t>4)
{if(key2==0);
{
if(key2==0)
{
beep_on;
delay_ms(100);
beep_off;
t=t-5;
OCR2=t;
delay_ms(200);
}
}
}
else //if(t==0)
{
if(key2==0)
{delay_ms(20);
if(key2==0)
{
OCR2=0;
beep_three();
delay_ms(200);
}
}
}
}
void beep_three(void)
{
beep_on;
delay_ms(95);
beep_off;
delay_ms(95);
beep_on;
delay_ms(95);
beep_off;
delay_ms(95);
beep_on;
delay_ms(95);
beep_off;
}
void scan_key(void)
{
scan_s1();
scan_s2();
}
void timer2_init(void)
{
TCCR2 = 0x00; //停止定时器
ASSR = 0x00; //异步时钟模式
TCNT2 = 0x00; //初始值
TIMSK |= 0x00; //中断允许
TCCR2 = 0x61; //启动定时器
}
void init_devices(void)
{
CLI(); //禁止所有中断
MCUCR = 0x00;
MCUCSR = 0x80; //禁止JTAG
GICR = 0x00;
port_init();
timer2_init();
SEI(); //开全局中断
}
void main(void)
{
init_devices();
while(1)
{
scan_key();
}
}