
你好很简单的,我先给你一个绘图的程序,其中函数picture()就是一个点一个点画上去的:
然后画点主要是要了解LCD12864的绘图工作原理
它先从(0x80+0)行开始(最左上角的点),然后每一行一共16字节,每一次写2字节,8次写完一行,写行的地址指针自动加1,手动换行,你只需要把上半屏写64次,下半屏写64次,就能画图了。
如果单就一个点,你可以这样:
void drew()
{
write_com(0x34);write_com(0x36);
write_com(0x80+0);write_com(0x80);
write_data(0x80);//第一行第一个点
write_com(0x80+0);write_com(0x88);
write_data(0x80);//第二屏第一行第一个点
}
函数同我程序中的picture(),只要看懂这个函数想画什么都没问题。
不懂的随时回复我。
希望我的回答能帮助到你。
#include "reg51h"
#define uchar unsigned char //定义unsigned char 为 uchar
#define uint unsigned int
sbit F1 = P3^0;
sbit F2 = P3^1;
uint time = 40; //通过改变TIME的参数可以改变流水灯的变换速度
/一微秒延时子程序/
void delayus(uint delay){
while(delay--);
}
/一毫秒延时子程序/
void delayms(uint delay){
while(delay--)
delayus(149);
}
/变换方式一 子函数 /
void run_LED_fun1()
{
uchar a,temp,temp1;
temp=0x01;
for(a=9;a>0;a--) //P1口LED灯依次点亮
{
P1=~temp;
delayms(time);
temp<<=1;
}
temp=0x01;
for(a=9;a>0;a--) //P3口LED灯依次点亮
{
P3=~temp;
delayms(time);
temp<<=1;
}
temp=0x01; //P2口LED灯依次反向点亮
for(a=9;a>0;a--)
{
P2=~temp;
delayms(time);
temp<<=1;
}
temp=0x80; //P0口LED灯依次反向点亮
for(a=9;a>0;a--)
{
P0=~temp;
delayms(time);
temp>>=1;
}
temp=0x01;
for(a=9;a>0;a--) //P0口LED灯依次点亮
{
P0=~temp;
delayms(time);
temp<<=1;
}
temp=0x80;
for(a=9;a>0;a--) //P2口LED灯依次点亮
{
P2=~temp;
delayms(time);
temp>>=1;
}
temp=0x80; //P3口LED灯依次反向点亮
for(a=9;a>0;a--)
{
P3=~temp;
delayms(time);
temp>>=1;
}
temp=0x80; //P1口LED灯依次反向点亮
for(a=9;a>0;a--)
{
P1=~temp;
delayms(time);
temp>>=1;
}
temp=0xfe;
for(a=8;a>0;a--)
{
P1=temp;
delayms(time);
temp<<=1;
}
temp=0xfe;
for(a=8;a>0;a--)
{
P3=temp;
delayms(time);
temp<<=1;
}
temp=0xfe;
for(a=8;a>0;a--)
{
P0=temp;
delayms(time);
temp<<=1;
}
temp=0x7f;
for(a=8;a>0;a--)
{
P2=temp;
delayms(time);
temp>>=1;
}
temp=0x01;
for(a=8;a>0;a--)
{
P2=temp;
delayms(time);
temp1=~temp;
temp1<<=1;
temp=~temp1;
}
temp=0x80;
for(a=8;a>0;a--)
{
P0=temp;
delayms(time);
temp1=~temp;
temp1>>=1;
temp=~temp1;
}
temp=0x80;
for(a=8;a>0;a--)
{
P3=temp;
delayms(time);
temp1=~temp;
temp1>>=1;
temp=~temp1;
}
temp=0x80;
for(a=8;a>0;a--)
{
P1=temp;
delayms(time);
temp1=~temp;
temp1>>=1;
temp=~temp1;
}
}
/变换方式二 子函数 /
void run_LED_fun2()
{
uchar a,temp,temp1,temp2;
temp=0x01;
temp1=0x80;
for(a=8;a>0;a--) //P1口LED灯依次点亮
{
P1=~temp;
P0=~temp;
P3=~temp1;
P2=~temp;
delayms(time);
temp<<=1;
temp1>>=1;
}
temp=0x80;
temp1=0x01;
for(a=8;a>0;a--) //P1口LED灯依次点亮
{
P1=~temp;
P0=~temp;
P3=~temp1;
P2=~temp;
delayms(time);
temp>>=1;
temp1<<=1;
}
temp=0xfe;
temp1=0x7f;
for(a=8;a>0;a--)
{
P1=temp;
P0=temp;
P3=temp1;
P2=temp;
delayms(time);
temp<<=1;
temp1>>=1;
}
temp=0x7f;
temp1=0xfe;
for(a=8;a>0;a--)
{
P1=~temp;
P0=~temp;
P3=~temp1;
P2=~temp;
delayms(time);
temp2=~temp;
temp>>=1;
temp2=~temp;
temp1<<=1;
}
}
/变换方式三 子函数 /
void run_LED_fun3()
{
P0=0x00;
P1=0xff;
P2=0xff;
P3=0xff;
delayms(5time);
P0=0xff;
P1=0x00;
P2=0xff;
P3=0xff;
delayms(5time);
P0=0xff;
P1=0xff;
P2=0xff;
P3=0x00;
delayms(5time);
P0=0xff;
P1=0xff;
P2=0x00;
P3=0xff;
delayms(5time);
P0=0xff;
P1=0x00;
P2=0xff;
P3=0x00;
delayms(5time);
P0=0x00;
P1=0xff;
P2=0x00;
P3=0xff;
delayms(5time);
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
}
/变换方式四 子函数 /
void run_LED_fun4()
{
uchar a,temp,temp1,temp2;
P0=0xff;
P1=0x00;
P2=0xff;
P3=0xff;
delayms(time);
temp=0xfe;
temp1=0xfe;
for(a=8;a>0;a--)
{
P1=~temp;
P3=temp1;
delayms(time);
temp2=~temp;
temp<<=1;
temp2=~temp;
temp1<<=1;
}
temp=0xfe;
temp1=0x7f;
for(a=8;a>0;a--)
{
P3=~temp;
P2=temp;
delayms(time);
temp2=~temp;
temp<<=1;
temp2=~temp;
temp1>>=1;
}
temp=0xfe;
temp1=0x7f;
for(a=8;a>0;a--)
{
P2=~temp;
P0=temp1;
delayms(time);
//temp2=~temp1;
temp<<=1;
//temp2=~temp;
temp1>>=1;
}
temp=0x7f;
temp1=0xfe;
for(a=8;a>0;a--)
{
P0=~temp;
P1=temp1;
delayms(time);
temp2=~temp;
temp>>=1;
temp2=~temp;
temp1<<=1;
}
}
/
void change_speed()
{
if(F1 == 0)
{
delayms(10);
if(F1 == 0)
{
while(!F1);
time = time +20;
}
}
if(F2 == 0)
{
delayms(10);
if(F2 == 0)
{
while(!F2);
time = time -20;
}
}
}
/
/主函数 /
void main()
{
while(1)
{
run_LED_fun1();
run_LED_fun2();
run_LED_fun3();
run_LED_fun4();
}
}
真正的并行处理是需要多个CPU的,而一般的单片机只有一个CPU是无法实现并行处理。
从你的问题来看,你需要的是多任务处理机制,这个是用一个嵌入式 *** 作系统就可以很容易的实现。P0和P1口分别有两个独立的任务来管理,这样就实现了同时处理并行问题
在51系列里面,有atmel公司开发了RTXY-51嵌入式 *** 作系统,代码量很小,keil编译器就可以直接编译,具体的资料可以查查,很容易入门的
以上就是关于求用12864画点、线的c语言并行单片机程序。全部的内容,包括:求用12864画点、线的c语言并行单片机程序。、利用单片机并行I/O口控制流水灯、单片机怎么处理两个要同时进行的问题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)