打印
[Atmel]

用AtmelStudio6.2跑mega16例程(58)8155扩展

[复制链接]
853|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ddllxxrr|  楼主 | 2014-11-25 20:39 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
以下是Proteus仿真截图:


以下是Studio6.2编译通过的截图:


程序清单:

/*
* GccApplication21.c
*
* Created: 2014-11-25 18:20:45
* Author: Administrator
*/

#define F_CPU 2000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdint.h>

#define COMM_8155 (uint8_t*)0xFD00 //命令字端口
#define PA_8155 (uint8_t*)0xFD01 //PA端口地址
#define PB_8155 (uint8_t*)0xFD02
#define PC_8155 (uint8_t*)0xFC00
#define CONT_8155_L8 (uint8_t*)0xFD04
#define CONT_8155_H8 (uint8_t*)0xFD05
#define PMEM_8155 (uint8_t*)0xFC00

#define BEEP() PORTB ^= _BV(PB0)

const uint8_t SEG_CODE[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF};

uint8_t Disp_Buffer[4] = {10,3,5,0};

volatile uint16_t cnt_8155 = 350;

enum OP_Type{ADD,SUB};

void Sounder()
{
uint8_t i;
for(i = 0; i<50; i++)
{
BEEP();_delay_us(160);
}
}



void Set_8155_TC()
{
*CONT_8155_L8 = (uint8_t)cnt_8155;
*CONT_8155_H8 = (uint8_t)(cnt_8155>>8);
*COMM_8155 = 0B11000011;
}

void adjust_tCount(enum OP_Type op)
{
uint8_t i;
uint16_t cnt;
cnt_8155=(op == ADD)? cnt_8155+50:cnt_8155 - 50;
if(cnt_8155 > 500) cnt_8155 = 500;
else if(cnt_8155 < 100) cnt_8155 = 100;
cnt = cnt_8155;
for(i=3;i>=1;i--)
{
Disp_Buffer[i] = cnt % 10;
cnt /=10;
}

}

void Key_Process()
{

uint8_t i;
static uint8_t Pre_Key_State = 0xFF;
uint8_t curr_Key_State = * PC_8155 | 0xF0;
if(Pre_Key_State == curr_Key_State)return;
Pre_Key_State = curr_Key_State;

switch(curr_Key_State)
{
case (uint8_t)~_BV(0):
adjust_tCount(ADD);
break;
case (uint8_t)~_BV(1):
adjust_tCount(SUB);
break;
case (uint8_t)~_BV(2):
Set_8155_TC();
break;
case (uint8_t)~_BV(3):
for(i=0;i<=100;i++)
{
*(PMEM_8155 +i) = i;
}
break;


}
}


int main(void)
{
uint8_t i;

DDRA = 0xFF;
DDRB = 0xFF;
DDRC = 0xFF;
DDRD = 0x00; PORTD = 0xFF;
MCUCR = 0x82;
*COMM_8155 = 0B00000011;
GICR = _BV(INT0);
sei();
while(1)
{
for(i = 0;i<4;i++)
{
*PB_8155 = 0x00;
*PA_8155 = SEG_CODE[Disp_Buffer[i]];
*PB_8155 = _BV(7-i);
_delay_ms(4);
Key_Process();
}
}
}


ISR(INT0_vect)
{
Sounder();
Set_8155_TC();
}


相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2398

主题

6956

帖子

67

粉丝